Reputation: 21
file to be tested: /a/b/c/api/localclass/s/taxinformationrepository.class.phptest:
/a/b/c/api/tests/_helpers/TestTaxInformationRepository_class.php
phpUnit directory location:
/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;
}
Then I run the test by command line:
-$./vendor/bin/phpunit /home/administrador/Documentos/api-es-front-01/tests/_helpers/TestTaxInformationRepository_class.php
And then I get the following:
PHPUnit 9.6.7 by Sebastian Bergmann and contributors.
W 1 / 1 (100%)
Time: 00:00.002, Memory: 4.00 MB
There was 1 warning:
- Warning No tests found in class "App\Tests\TestTaxInformationRepository_class".
WARNINGS!
Tests: 1, Assertions: 0, Warnings: 1.
Why is not finding the test? I expected something like:
PHPUnit 9.6.7 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 00:00.113, Memory: 4.00 MB
There was 1 failure:
- App\Tests\TestTaxInformationRepository_class::getConceptInputsAnnual_lePasoArrayDevuelveString
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'hola'
+'(large amount of data)'/a/b/c/api/tests/_helpers/TestTaxInformationRepository_class.php:14
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Upvotes: 1
Views: 48
Reputation: 21
I could solve the issue by adding
/** @test */
before the function
Thanks!
Upvotes: 1