znt/module/file/test/model/filemtime.php

60 lines
1.8 KiB
PHP
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
title=测试 fileModel::fileMTime();
timeout=0
cid=16500
- 步骤1传入空对象 @0
- 步骤2传入存在的文件对象 @1
- 步骤3传入不存在的文件路径 @0
- 步骤4传入空字符串的realPath @0
- 步骤5传入null作为realPath @0
*/
// 1. 导入依赖
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/model.class.php';
// 2. 用户登录
su('admin');
// 3. 创建测试实例
$fileTest = new fileModelTest();
// 4. 准备测试数据
$testFile = dirname(__FILE__) . '/test_filemtime.txt';
$testContent = 'This is a test file for fileMTime method testing.';
file_put_contents($testFile, $testContent);
$actualMTime = filemtime($testFile);
// 创建不同的文件对象用于测试
$validFile = new stdclass();
$validFile->realPath = $testFile;
$emptyFile = new stdclass();
$missingRealPathFile = new stdclass();
$missingRealPathFile->someOtherProperty = 'test';
$nonexistentFile = new stdclass();
$nonexistentFile->realPath = dirname(__FILE__) . '/nonexistent_file.txt';
$emptyPathFile = new stdclass();
$emptyPathFile->realPath = '';
$nullPathFile = new stdclass();
$nullPathFile->realPath = null;
// 5. 执行测试步骤至少5个
r($fileTest->fileMTimeTest($emptyFile)) && p() && e('0'); // 步骤1传入空对象
r($fileTest->fileMTimeTest($validFile) > 0) && p() && e('1'); // 步骤2传入存在的文件对象
r($fileTest->fileMTimeTest($nonexistentFile)) && p() && e('0'); // 步骤3传入不存在的文件路径
r($fileTest->fileMTimeTest($emptyPathFile)) && p() && e('0'); // 步骤4传入空字符串的realPath
r($fileTest->fileMTimeTest($nullPathFile)) && p() && e('0'); // 步骤5传入null作为realPath
// 清理测试文件
if(file_exists($testFile)) unlink($testFile);