Skip to content

Commit

Permalink
allow phpunit8, fix namespaces and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodic committed Apr 23, 2020
1 parent e665c56 commit 196d797
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 11 deletions.
1 change: 1 addition & 0 deletions .phpunit.result.cache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C:37:"PHPUnit\Runner\DefaultTestResultCache":1962:{a:2:{s:7:"defects";a:7:{s:98:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testBeforeFirstTestBehaviour";i:5;s:93:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testBeforeTestBehaviour";i:5;s:92:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testAfterTestBehaviour";i:5;s:96:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testAfterLastTestBehaviour";i:5;s:92:"IntegrationTesting\Tests\Integration\MariaDB\PDOIntegrationTest::testReadFixtureFromDatabase";i:5;s:124:"IntegrationTesting\Tests\Integration\MariaDB\PDOWithoutBeforeOrAfterTestFixturesTest::testReadingEphemeralTableHasNoContents";i:5;s:137:"IntegrationTesting\Tests\Integration\MariaDB\PDOWithoutBeforeOrAfterTestFixturesTest::testPersistentTableHasRowCountEqualsToTestsExecuted";i:3;}s:5:"times";a:9:{s:98:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testBeforeFirstTestBehaviour";d:0.005;s:93:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testBeforeTestBehaviour";d:0.005;s:92:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testAfterTestBehaviour";d:0.02;s:96:"IntegrationTesting\PHPUnit\Runner\Extension\PDODatabaseExtensionTest::testAfterLastTestBehaviour";d:0.005;s:92:"IntegrationTesting\Tests\Integration\MariaDB\PDOIntegrationTest::testReadFixtureFromDatabase";d:0.006;s:124:"IntegrationTesting\Tests\Integration\MariaDB\PDOWithoutBeforeOrAfterTestFixturesTest::testReadingEphemeralTableHasNoContents";d:0.002;s:137:"IntegrationTesting\Tests\Integration\MariaDB\PDOWithoutBeforeOrAfterTestFixturesTest::testPersistentTableHasRowCountEqualsToTestsExecuted";d:0.011;s:121:"IntegrationTesting\Tests\Integration\MariaDB\PDOWithoutBeforeOrAfterTestFixturesTest::testPersistentTableHasAtLeastOneRow";d:0.002;s:100:"IntegrationTesting\Tests\Integration\MariaDB\PDOIntegrationTest::testPersistentTableHasAtLeastOneRow";d:0.002;}}}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"ext-mbstring": "*",
"ext-pdo_mysql": "*",
"ext-xml": "*",
"phpunit/phpunit": "^9.0",
"phpunit/phpunit": "^8.5",
"friendsofphp/php-cs-fixer": "^2.16",
"squizlabs/php_codesniffer": "^3.5"
},
Expand Down
1 change: 1 addition & 0 deletions src/Driver/FileSystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ArrayIterator;
use FilesystemIterator;
use IntegrationTesting\Exception\TestingException;
use Iterator;

class FileSystem
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/TestingException.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace IntegrationTesting\Driver;
namespace IntegrationTesting\Exception;

class TestingException extends \Exception
{
Expand Down
2 changes: 1 addition & 1 deletion src/PHPUnit/Runner/Extension/PDODatabaseExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use IntegrationTesting\Driver\FileSystem;
use IntegrationTesting\Driver\PDOConnection;
use IntegrationTesting\Driver\TestingException;
use IntegrationTesting\Exception\TestingException;
use PHPUnit\Runner\BeforeFirstTestHook;
use PHPUnit\Runner\BeforeTestHook;
use PHPUnit\Runner\AfterTestHook;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace IntegrationTesting\PHPUnit\Runner\Extension;

use IntegrationTesting\Driver\TestingException;
use IntegrationTesting\Exception\TestingException;

class PDODatabaseExtensionConfig
{
Expand Down
3 changes: 2 additions & 1 deletion tests/fixtures/before-first-test/01.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ CREATE TABLE IF NOT EXISTS `test`.`ephemeral_table`

CREATE TABLE IF NOT EXISTS `test`.`persistent_table`
(
`id` INT NOT NULL AUTO_INCREMENT,
`id` INT NOT NULL AUTO_INCREMENT,
`varchar` VARCHAR(45) NULL,
PRIMARY KEY (`id`)
);
2 changes: 1 addition & 1 deletion tests/fixtures/before-test/01.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-- in this example we truncate also before each test
TRUNCATE TABLE `test`.`ephemeral_table`;

INSERT INTO `test`.`persistent_table` (`id`) VALUES (NULL);
INSERT INTO `test`.`persistent_table` (`varchar`) VALUES ('example');
16 changes: 15 additions & 1 deletion tests/integration/MariaDB/PDOIntegrationTest.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace IntegrationTesting\Tests\Integration;
namespace IntegrationTesting\Tests\Integration\MariaDB;

use IntegrationTesting\Driver\PDOConnection;
use IntegrationTesting\WithAfterTestFixtureName;
Expand Down Expand Up @@ -39,4 +39,18 @@ public function testReadFixtureFromDatabase(): void
$data
);
}

public function testPersistentTableHasAtLeastOneRow(): void
{
$conn = new PDOConnection(
constant('DB_DSN'),
constant('DB_USERNAME'),
constant('DB_PASSWORD')
);
$conn->PDO()->beginTransaction();
$statement = $conn->PDO()->query("SELECT * FROM `test`.`persistent_table`");
$conn->PDO()->commit();
// this is the third test to run a beforeTest hook!
$this->assertTrue($statement->rowCount() >= 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace IntegrationTesting\Tests\Integration;
namespace IntegrationTesting\Tests\Integration\MariaDB;

use IntegrationTesting\Driver\PDOConnection;
use PHPUnit\Framework\TestCase;
Expand All @@ -11,7 +11,6 @@
*/
final class PDOWithoutBeforeOrAfterTestFixturesTest extends TestCase
{

public function testReadingEphemeralTableHasNoContents(): void
{
$conn = new PDOConnection(
Expand All @@ -23,15 +22,17 @@ public function testReadingEphemeralTableHasNoContents(): void
$this->assertSame(0, $statement->rowCount());
}

public function testPersistentTableHasRowCountEqualsToTestsExecuted(): void
public function testPersistentTableHasAtLeastOneRow(): void
{
$conn = new PDOConnection(
constant('DB_DSN'),
constant('DB_USERNAME'),
constant('DB_PASSWORD')
);
$conn->PDO()->beginTransaction();
$statement = $conn->PDO()->query("SELECT * FROM `test`.`persistent_table`");
$conn->PDO()->commit();
// this is the third test to run a beforeTest hook!
$this->assertSame(3, $statement->rowCount());
$this->assertTrue($statement->rowCount() >= 1);
}
}

0 comments on commit 196d797

Please sign in to comment.