cakephp 未能找到获取错误类的单元测试

l7mqbcuq  于 2022-11-11  发布在  PHP
关注(0)|答案(1)|浏览(154)

我有一个dynamoDB的位置类

src/Dynamo/shop.php

我的类如下所示

<?php

    namespace App\Dynamo;

    class Shop
    {
        -----
    }

?>

我试图实现这个类的单元测试,所以我在下面的位置创建了一个文件夹类发电机。

app/cake/tests/TestCase/Dynamo

在Dynamo文件夹中,我创建了一个文件名为ShopTest.php的类
为了创建一个单元测试,我编写了如下的类

<?php
declare(strict_types=1);

namespace App\Test\TestCase\Dynamo;

use App\Dynamo\Shop;
use Cake\TestSuite\TestCase;

class ShopTest{

    public function setUp()
    {
        $this->shop = new Shop;
    }

    public function testconnectDynamoDB()
    {
        debug($this->shop->connectDynamoDB());

        $this->assertNotEmpty($this->shop->connectDynamoDB());

    }
}

现在运行phpunit命令后

vendor/bin/phpunit tests/TestCase/Dynamo/ShopTest.php

我越来越

Class 'App\Test\TestCase\Dynamo\ShopTest' could not be found in '/var/www/html/tests/TestCase/Dynamo/ShopTest.php'.

此位置存在类,为什么找不到我正在获取的类?

root@0ceda1df4444:/var/www/html# cd /var/www/html/tests/TestCase/Dynamo/
    root@0ceda1df4444:/var/www/html/tests/TestCase/Dynamo# ls
    ShopTest.php

root@0ceda1df4444:/var/www/html/tests/TestCase/Dynamo# cat ShopTest.php 
<?php
declare(strict_types=1);

namespace App\Test\TestCase\Dynamo;

use App\Dynamo\Shop;
use Cake\TestSuite\TestCase;

class ShopTest{

此外,我试图通过以下命令运行所有测试用例,我收到一个警告。

root@0ceda1df4444:/var/www/html# vendor/bin/phpunit                
PHPUnit 9.5.9 by Sebastian Bergmann and contributors.

Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

No tests executed!
oug3syen

oug3syen1#

没有测试类

这里的错误信息有点令人困惑,但症结在于这不是一个测试类:

<?php
declare(strict_types=1);

namespace App\Test\TestCase\Dynamo;

use App\Dynamo\Shop;
use Cake\TestSuite\TestCase;

class ShopTest{ # <--

它只是一个类(其名称中碰巧包含单词Test)。
请与文档中的示例进行比较:

namespace App\Test\TestCase\View\Helper;

use App\View\Helper\ProgressHelper;
use Cake\TestSuite\TestCase;
use Cake\View\View;

class ProgressHelperTest extends TestCase # <--
{

若要侦测为测试,类别必须扩充TestClass-因此,若要修正此问题:

...
use App\Dynamo\Shop;
use Cake\TestSuite\TestCase;

class ShopTest extends TestCase # <--
{

通过该更改,测试类将加载,一些更容易解决的问题将变得明显:

$ vendor/bin/phpunit tests/TestCase/Dynamo/ShopTest.php
PHP Fatal error:  Declaration of ShopTest::setUp() must be compatible with Cake\TestSuite\TestCase::setUp(): void in ~/repos/cakephp/app/tests/TestCase/Dynamo/ShopTest.php on line 11

Fatal error: Declaration of ShopTest::setUp() must be compatible with Cake\TestSuite\TestCase::setUp(): void in ~/repos/cakephp/app/tests/TestCase/Dynamo/ShopTest.php on line 11

相关问题