Skip to content

Commit

Permalink
Merge branch 'cake3-next' into cake3
Browse files Browse the repository at this point in the history
# Conflicts:
#	src/FixtureManager.php
  • Loading branch information
Juan Pablo Ramirez committed Feb 3, 2021
2 parents 5e58fa1 + c8eab96 commit 5da9516
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 56 deletions.
19 changes: 18 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ by SQL queries. These are called `TableSniffers` and there are located in the `s
* Postgres

If you use a different database engine, you will have to provide your own. It should extend
the `BaseTableSniffer`.
the `BaseTableSniffer` class.

You should then map in your `config/test_suite_light.php` file the driver to
the custom table sniffer. E.g.:
Expand All @@ -85,6 +85,23 @@ You may wish to skip the truncation of tables between the tests. For example if
your tests do not interact with the database, or if you do not mind having a dirty DB at the beginning of your tests.
This is made at the test class level, by letting your test class using the trait `CakephpTestSuiteLight\SkipTablesTruncation`.

### Temporary vs non-temporary dirty table collector

The present plugin collects the dirty tables in a dedicated table with the help of triggers.
This table is per default temporary in order to keep it invisible to the code.

One of the advantage of the present test suite, consists in the fact that the test database is cleaned before each test,
rather than after. This enables the developer to perform queries in the test database and observe the state in which
a given test left the database.

Due to the fact that triggers are created on all tables creating inserts in the temporary dirty table collector,
the developer will not be able to perform any manual inserts in the test database outside the test suite.

If needed, one solution consists in dropping the test database and re-running the migrations. A second solution
consists in having the dirty table collector non-temporary. This is possible at the connection level, by
calling in `tests/bootstrap.php` `CakephpTestSuiteLight\Sniffer\SnifferRegistry::get('your_test_connection_name')->activateMainMode();`
with `your_test_connection_name` being typically `test`.

### Using CakePHP fixtures

It is still possible to use the native CakePHP fixtures. To this aim, you may simply load them as described [here](https://book.cakephp.org/3/en/development/testing.html#creating-fixtures).
Expand Down
39 changes: 0 additions & 39 deletions src/FixtureManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,6 @@ class FixtureManager extends BaseFixtureManager
*/
private $activeConnections;

/**
* FixtureManager constructor.
* The config file test_suite_light is being loaded
* This config file is deprecated. Configure the suite
* at the connection level.
*/
public function __construct()
{
$this->loadConfig();
}

/**
* @param string $name
* @return ConnectionInterface
Expand Down Expand Up @@ -101,34 +90,6 @@ public function skipConnection(string $connectionName, array $ignoredConnections
return true;
}

/**
* Load the mapping between the database drivers
* and the table truncators.
* Add your own truncators for a driver not being covered by
* the package in your test_suite_light.php config file
* @deprecated The configuration file test_suite_light.php is deprecated
*/
public function loadConfig(): FixtureManager
{
if (!self::$_configIsLoaded) {
try {
if (Configure::load('test_suite_light')) {
throw new \PHPUnit\Framework\Exception(
"The test_suite_light.php configuration file is deprecated.\n" .
"See https://github.com/vierge-noire/cakephp-test-suite-light#cakephp-test-suite-light.\n"
);
}
}
catch (\PHPUnit\Framework\Exception $exception) {
echo $exception->getMessage();
}
catch (Exception $exception) {}
self::$_configIsLoaded = true;
}

return $this;
}

/**
* Get the appropriate sniffer and drop all tables
* @param string $connectionName
Expand Down
11 changes: 0 additions & 11 deletions tests/TestApp/config/test_suite_light.php

This file was deleted.

7 changes: 2 additions & 5 deletions tests/TestCase/FixtureManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,9 @@ public function testConnectionIsTest()
);
}

public function testLoadSnifferFromConfigFile()
public function testSkipInTestSuiteLight()
{
$expected = '\testTableSniffer';
$this->FixtureManager->loadConfig();
$conf = Configure::readOrFail('TestSuiteLightSniffers.\testDriver');
$this->assertEquals($expected, $conf);
$this->assertSame(true, ConnectionManager::getConfig('test_dummy')['skipInTestSuiteLight']);
}

public function testFetchActiveConnections()
Expand Down
1 change: 1 addition & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
// This connection is meant to be ignored
$dummyConnection = $dbConnection;
$dummyConnection['driver'] = 'Foo';
$dummyConnection['skipInTestSuiteLight'] = true;
ConnectionManager::setConfig('test_dummy', $dummyConnection);


Expand Down

0 comments on commit 5da9516

Please sign in to comment.