Ergebnis 1 bis 2 von 2

Thema: contao/test-case - richtige Anwendung

  1. #1
    Contao-Fan Avatar von Ernestopheles
    Registriert seit
    25.10.2019.
    Ort
    Hamburg
    Beiträge
    293
    Contao-Projekt unterstützen

    Support Contao

    Standard contao/test-case - richtige Anwendung

    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

  2. #2
    Contao-Nutzer
    Registriert seit
    10.06.2021.
    Beiträge
    242
    Contao-Projekt unterstützen

    Support Contao

    Standard

    Ich hab test-case zwar noch nie benutzt, aber ich würde davon ausgehen, dass du test-case 4.13 brauchst statt 5.1.

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •