Hat jemand ein Beispiel für eine Contao extension, die PHPUnit verwendet und dabei contao/test-case benutzt?
Ich bekomme keinen Framework Mock weil:
Cannot find the Contao configuration file
Meine Testklasse:
PHP-Code:
<?php
declare(strict_types=1);
namespace Nahati\ContaoIsotopeStockBundle\Tests\Unit\Helper;
use Contao\TestCase\ContaoTestCase;
use nahati\ContaoIsotopeStockBundle\Helper\Helper;
use Isotope\Model\Product\Standard;
Danke für Hinweise und Hilfe
/**
* Test the Helper class.
*
* @covers \nahati\ContaoIsotopeStockBundle\Helper\Helper
*/
class HelperTest extends ContaoTestCase
{
private $helper;
protected function setUp(): void
{
parent::setUp();
// Mocks a Symfony container with the default configuration of the Contao core extension
$container = $this->getContainerWithContaoConfiguration();
// Check if the container has been created
$this->assertInstanceOf('\Symfony\Component\DependencyInjection\ContainerBuilder', $container);
// Check if the container is working
$this->assertEquals($container->getParameter('contao.upload_path'), "files");
$framework = $this->mockContaoFramework();
// Check if the framework has been created
$this->assertInstanceOf('\Contao\CoreBundle\Framework\ContaoFramework&\PHPUnit\Framework\MockObject\MockObject', $framework);
$this->helper = new Helper();
}
public function testTrueIsTrue()
{
$foo = true;
$this->assertTrue($foo);
}
}
Ergibt:
RuntimeException: Cannot find the Contao configuration file
Die asserts vor dem mockContaoFramework() sind ok.
Der ContaoTestCase steigt in loadDefaultConfiguration() im default Zweig aus und wirft die Exception. Es wird das Configuration file nicht gefunden, wie schon die Fehlermeldung sagt.
Ich denke der passende Case wäre
The test-case is the root package and the core-bundle folder is in vendor/contao
Jedoch findet sich dieser Pfad in meiner Installation nicht wieder:
PHP-Code:
// The test-case is the root package and the core-bundle folder is in vendor/contao
case file_exists(__DIR__.'/../vendor/contao/core-bundle/contao/config/default.php'):
include __DIR__.'/../vendor/contao/core-bundle/contao/config/default.php';
break;
Unter /vendor/contao/core-bundle gibt es kein contao
Contao 4.13.23 PHP 8.1
PHPUnit 9.5.28, test-case ^5.1
Lesezeichen