使用 Codeception 进行单元测试:解析错误

我正在尝试为我的简单网站编写一些单元测试(用于研究)。

项目结构:

http://img1.mukewang.com/64ba403b00014ef405070959.jpg

在index.php 里面我有一个namespace Main定义。


函数位于namespace Main\Logic,类位于namespace Main\Logic\Classes。


代码tests/unit/BuildGalleryTest.php:


<?php


namespace 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>";

        }


我究竟做错了什么?可以采取什么措施来解决这个问题?


翻阅古今
浏览 100回答 1
1回答

墨色风雨

我已经使用 sphp 将 php 版本更改为 7.4,现在一切正常!
打开App,查看更多内容
随时随地看视频慕课网APP