vierge-noire / cakephp-test-suite-light

A fast test suite for CakePHP applications
MIT License
13 stars 7 forks source link

Pipelines #55

Closed mcube27 closed 2 years ago

mcube27 commented 2 years ago

Hi,

I use Cakephp 4.2.10 and "vierge-noire/cakephp-fixture-factories": "2.5"

I am using Bibucket pipelines with docker images to perform tests.

When I want to do my tests using a docker image for the database, it does not work with the php unit listeners of CakephpTestSuiteLight.

I get this :

Exception: Unable to insert fixture "App\Test\Fixture\UsersFixture" in "App\Test\TestCase\IntegrationTests\BookingsIntegrationTest" test case: 
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mcube27_jmstest.users' doesn't exist
In [C:\webserver\www\weeezy-api\vendor\vierge-noire\cakephp-test-suite-light\src\FixtureManager.php, line 181]

And I get this cli_error message :

Caused by: [PDOException] SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mcube27_jmstest.users' doesn't exist in C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Statement\MysqlStatement.php on line 39
Stack Trace:
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Statement\MysqlStatement.php:39
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Connection.php:337
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Core\Retry\CommandRetry.php:70
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Connection.php:340
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Query.php:250
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\TestSuite\Fixture\TestFixture.php:344
- C:\webserver\www\weeezy-api\vendor\vierge-noire\cakephp-test-suite-light\src\FixtureManager.php:173
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Connection.php:723
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Core\Retry\CommandRetry.php:70
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Connection.php:729
- C:\webserver\www\weeezy-api\vendor\vierge-noire\cakephp-test-suite-light\src\FixtureManager.php:184
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\Database\Connection.php:682
- C:\webserver\www\weeezy-api\vendor\vierge-noire\cakephp-test-suite-light\src\FixtureManager.php:185
- C:\webserver\www\weeezy-api\vendor\cakephp\cakephp\src\TestSuite\Fixture\FixtureInjector.php:101
- C:\webserver\www\weeezy-api\vendor\vierge-noire\cakephp-test-suite-light\src\FixtureInjector.php:75
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\Framework\TestResult.php:424
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\Framework\TestResult.php:644
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\Framework\TestCase.php:838
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\Framework\TestSuite.php:626
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\Framework\TestSuite.php:626
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\TextUI\TestRunner.php:656
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\TextUI\Command.php:235
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\src\TextUI\Command.php:194
- C:\webserver\www\weeezy-api\vendor\phpunit\phpunit\phpunit:98

But it works if I reverse back to cakephp normal listener.

I ran it on my computer with docker using this to start the database server docker run --name mariadblatest --env MARIADB_ROOT_PASSWORD=secret --env MARIADB_USER=dev --env MARIADB_DATABASE=test --env MARIADB_PASSWORD=test -p 3306:3306 mariadb:latest

I have been searching for 2 hours but I do not understand. Maybe the triggers are not set on the database ?

Thank you very much !

mcube27 commented 2 years ago

When I use WAMP on my computer, everything works like a charm. it's only with the docker setup.

pabloelcolombiano commented 2 years ago

@mcube27 if I get you well, you also get an error when running on docker locally, right?

The error reported Base table or view not found: 1146 Table 'mcube27_jmstest.users' doesn't exist suggest that your database in named mcube27_jmstest while on your docker command, the database is test. Could this be due to some configuration of your Datasources?

For info, the pipelines of the fixture factories run with the test suite light, as shown here. The test suite light should trigger issues on docker.

mcube27 commented 2 years ago

Hi,

Yes locally on docker.

I change the name of the database for the docker line in this issue report. I used the mcube27_jmstest for my tests.

I did not understand what you said about test suite light triggering issues on docker ?

pabloelcolombiano commented 2 years ago

Which version of CakePHP are you using? How do you create the schema of your test DB? Do you use the Migrator? How does your phpunit.xml look like?

mcube27 commented 2 years ago

I use Cakephp 4.2.10

I use the fields in the fixtures. I have issues with the Migrator on going and can't use it without it triggering errors.

<?xml version="1.0" encoding="UTF-8"?>
<phpunit
    colors="true"
    processIsolation="false"
    stopOnFailure="false"
    bootstrap="./tests/bootstrap.php"
    >
    <php>
        <ini name="memory_limit" value="-1"/>
        <ini name="apc.enable_cli" value="1"/>
    </php>

    <!-- Add any additional test suites you want to run here -->
    <testsuites>
        <testsuite name="App Test Suite">
            <directory>./tests/TestCase</directory>
        </testsuite>
        <!--<testsuite name="pipeline">
            <directory>./tests/TestCase/UnitTests/SendinBlueTransportUnitTest.php</directory>
        </testsuite>-->
        <!-- Add plugin test suites here. -->
    </testsuites>

    <!-- Setup a listener for fixtures -->
    <listeners>
        <listener class="CakephpTestSuiteLight\FixtureInjector">
            <arguments>
                <object class="CakephpTestSuiteLight\FixtureManager" />
            </arguments>
        </listener>
    </listeners>

    <!-- Ignore vendor tests in code coverage reports -->
    <filter>
        <whitelist>
            <directory suffix=".php">src/</directory>
            <directory suffix=".php">plugins/*/src/</directory>
            <exclude>
                <file>src/Console/Installer.php</file>
            </exclude>
        </whitelist>
    </filter>
    <logging>
        <log type="testdox-text" target="php://stdout"/>
    </logging>
</phpunit>
pabloelcolombiano commented 2 years ago

Thanks for the additional input.

I am not sure on how the test suite light reacts with the schema creation using the fields in the fixtures. There should be no problem, but I am a bit out of time right now to investigate.

How do you manage your productive database? With migrations? If So, I would suggest fixing the issues you are having with the migrator, since this is anyway from CakePHP 4.3 the recommended approach. I can assist you there if needed. What were the issues you encountered?

mcube27 commented 2 years ago

I understand. I can use it like this as it works with the standard Cakephp listeners for phpuni

I have an open issue for the migrator : https://github.com/cakephp/cakephp/issues/16373

pabloelcolombiano commented 2 years ago

The issue you cite is not related to the Migrator. I would suggest using Vierge Noire's Migrator to manage the schema of your test DB.

Once in CakePHP 4.3, you can switch to the CakePHP Migrator tool.

mcube27 commented 2 years ago

I prefer to wait that my issues to switch to cakephp 4.3 are resolved.

I have another issue with the migrator but wait on this one.

Thanks !

pabloelcolombiano commented 2 years ago

Issues are always welcome, so if you ever want to report the one you had on the migrator here, feel free to do so here.