我正在尝试为我的简单网站编写一些单元测试(用于研究)。项目结构:在index.php 里面我有一个namespace Main定义。函数位于namespace Main\Logic,类位于namespace Main\Logic\Classes。代码tests/unit/BuildGalleryTest.php:<?phpnamespace Tests\Unit;use Codeception\Test\Unit as TestCase;use function Main\Logic\galleryBuilder;require "/Users/l.marder/Homeworks/php-study/lesson4/logic/galleryBuilder.php";class BuildGalleryTest extends TestCase{ /** * @dataProvider buildGalleryDataProvider * @param string $imgPack * @param string $expectedResponse */ public function testBuildGallery(string $imgPack, string $expectedResponse): void { $actualResponse = galleryBuilder("tests/unit/test_data/img/$imgPack"); self::assertEquals($expectedResponse, $actualResponse); } public function buildGalleryDataProvider(): array { return [ "Data pack 1: one pic" => [ "1", $this->buildTestGallery("1") ], "Data pack 2: two pics with folder and text.txt file" => [ "2", $this->buildTestGallery("2") ], "Data pack 3: no images" => [ "3", $this->buildTestGallery("3") ] ]; } private function buildTestGallery(string $dataPack): string { if ($dataPack === "1") { return " <a href=\"picture.php?img=tests/unit/test_data/img/1/1.img\" target=\"_blank\"> <div class=\"small-pic\"> <img class=\"img-small-kit\" src= alt=\"Kitty 2\"> </div> </a>"; }我究竟做错了什么?可以采取什么措施来解决这个问题?
添加回答
举报
0/150
提交
取消