提问人:fuego 提问时间:5/9/2023 更新时间:5/11/2023 访问量:37
命名空间与 phpUnit 冲突
Namespace conflict with phpUnit
问:
要测试的文件: /A/B/C/API/LOCALCLASS/S/TAXINFORMATIONREPOSITORY.class.phptest:
/a/b/c/api/tests/_helpers/TestTaxInformationRepository_class.php
phpUnit 目录位置:
/a/b/c/api/phpUnit/
composer.json:
{
"require": { "phpunit/phpunit": "^9.6" }, "autoload": { "psr-4": {"App\\\\": "/a/b/c/api/localclass/s/"} }, "autoload-dev": { "psr-4": {"App\\\\Tests\\\\": "/a/b/c/api/tests/\_helpers/"} }
}
TestTaxInformationRepository_class.php:
<?php
namespace App\Tests;
use App\S_TaxInformationRepository;
use PHPUnit\Framework\TestCase;
class TestTaxInformationRepository_class extends TestCase{
public function GetConceptInputsAnnual_lePasoArrayDevuelveString(): void
{
$getConceptInputsAnnualArray=['year' => 2022, 'account' => '4600015', 'accountMatrixPosition' => "when '46000015' then (1)"];
$taxinformationrepository_class=new S_TaxInformationRepository();
$resultado=$taxinformationrepository_class->getConceptInputsAnnual($getConceptInputsAnnualArray);
$this->assertEquals('hola',$resultado);
}
}
taxinformationrepository.class.php:
<?php
namespace App;
public static function getConceptInputsAnnual($conditionsArray)
{
$resultData = [];
$year = $conditionsArray["year"];
$account = $conditionsArray["account"];
$accountMatrixPosition = $conditionsArray['accountMatrixPosition'];
$sql = "SELECT tblCO.COCODIGO AS 'col01',
tblGM.GMSPCODE AS 'col02',
tblCY.CYCCY AS 'col03',
'' AS 'col04',
CONCAT(SUBSTRING(tblGM.GMOPEDATE,7,2),'/', SUBSTRING(tblGM.GMOPEDATE,5,2), '/',SUBSTRING(tblGM.GMOPEDATE,1,4)) AS 'col05',
tblGM.GMVOLUME AS 'col06',
tblGM.GMPRICE AS 'col07',
(tblGM.GMCORRETAJE + tblGM.GMLIQUIDADORCOM + tblGM.GMCONTRATACIONCOM + tblGM.GMGESTIONCOM + tblGM.GMSCLCOM
+ tblGM.GMOTHERSCOM + tblGM.GMCLIENTCOM + tblGM.GMTOBINTAX) AS 'col08',
(tblGM.GMEXCHANGE * tblGM.GMGROSSAMOUNT) AS 'col09',
tblGM.GMGROSSAMOUNT AS 'col10',
CASE GMSPCODE
{$accountMatrixPosition}
END AS 'col11',
tblGM.GMISIN AS 'colTo_isin',
tblGM.GMCODOPERATION AS 'colTo_opeCode',
tblGM.GMTIPOMOV AS 'colTo_isAnulated',
tblGM.GMEXCHANGE AS 'colTo_exchangeRate',
tblGM.GMCCY AS 'colTo_DivisaCode'
FROM BAGCMOVEMENT AS tblGM
LEFT JOIN (SELECT
COSIGNOTITULOS,
COCODIGO,
ROW_NUMBER() OVER (PARTITION BY COCODIGO ORDER BY COINDEX) AS code_rn
FROM BACONCEPTOSTMP) tblCO ON
tblGM.GMTYPE = tblCO.COCODIGO AND tblCO.code_rn = 1
LEFT JOIN BACCY AS tblCY ON
tblGM.GMCCY = tblCY.CYCODE
WHERE tblGM.GMSPCODE IN ({$account}) AND
tblCO.COSIGNOTITULOS = '+'
AND tblCO.COCODIGO IS NOT NULL
AND YEAR(CONVERT(DATE, tblGM.GMOPEDATE)) = {$year}
ORDER BY tblGM.GMOPEDATE, 'colTo_isin' ASC;";
$resultData = SQL::fetchAll($sql, 'BACKOFFICE', Config::get('BKDB', 'SQL'));
return $resultData;
}
然后我通过命令行运行测试:
-$./vendor/bin/phpunit /home/administrador/Documentos/api-es-front-01/tests/_helpers/TestTaxInformationRepository_class.php
然后我得到以下内容:
PHPUnit 9.6.7 由 Sebastian Bergmann 和贡献者编写。
W 1 / 1 (100%)
时间: 00:00.002, 内存: 4.00 MB
有 1 个警告:
- 警告 在类“App\Tests\TestTaxInformationRepository_class”中找不到任何测试。
警告!
测试:1,断言:0,警告:1。
为什么找不到测试?我期望像这样:
PHPUnit 9.6.7 由 Sebastian Bergmann 和贡献者编写。
F 1 / 1 (100%)
时间: 00:00.113, 内存: 4.00 MB
有 1 次失败:
- App\Tests\TestTaxInformationRepository_class::getConceptInputsAnnual_lePasoArrayDevuelveString
断言两个字符串相等失败。
--- 预期
+++ 实际
@@ @@
-'hola' +'(大量数据)'/a/b/c/api/tests/_helpers/TestTaxInformationRepository_class.php:14
失败!
测试:1,断言:1,失败:1。
答:
1赞
fuego
5/11/2023
#1
我可以通过添加
/** @test */
在函数之前
谢谢!
评论
test