Skip to content

Commit

Permalink
updated tests for phpunit deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
brainfoolong committed Apr 1, 2024
1 parent c6a07db commit b804a1f
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 89 deletions.
26 changes: 7 additions & 19 deletions appdata/modules/FramelixTests/tests/Db/BasicTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Framelix\Framelix\DateTime;
use Framelix\Framelix\Db\Sql;
use Framelix\FramelixTests\TestCaseDbTypes;
use PHPUnit\Framework\Attributes\Depends;
use ReflectionClass;

use function fopen;
Expand All @@ -25,9 +26,7 @@ public function testCreate(): void
$this->createTestTable();
}

/**
* @depends testCreate
*/
#[Depends("testCreate")]
public function testConditions()
{
$db = $this->getDb();
Expand Down Expand Up @@ -152,9 +151,7 @@ public function testConditions()
$db->query("DROP TABLE $table");
}

/**
* @depends testConditions
*/
#[Depends("testConditions")]
public function testQueries(): void
{
Sql::$logExecutedQueries = true;
Expand Down Expand Up @@ -228,9 +225,7 @@ public function testQueries(): void
$this->assertCount(2, $db->fetchArray("SELECT text_a FROM $table", null, 2));
}

/**
* @depends testQueries
*/
#[Depends("testQueries")]
public function testExceptionDbQuery()
{
$db = $this->getDb();
Expand All @@ -244,9 +239,7 @@ public function testExceptionDbQuery()
});
}

/**
* @depends testExceptionDbQuery
*/
#[Depends("testExceptionDbQuery")]
public function testExceptionNotExistingFetchIndex()
{
$this->assertExceptionOnCall(function () {
Expand All @@ -255,9 +248,7 @@ public function testExceptionNotExistingFetchIndex()
});
}

/**
* @depends testExceptionNotExistingFetchIndex
*/
#[Depends("testExceptionNotExistingFetchIndex")]
public function testExceptionUnsupportedDbValue()
{
$this->assertExceptionOnCall(function () {
Expand All @@ -267,10 +258,7 @@ public function testExceptionUnsupportedDbValue()
});
}

/**
* Drop tables after execution
* @depends testExceptionUnsupportedDbValue
*/
#[Depends("testExceptionUnsupportedDbValue")]
public function testCleanup(): void
{
$this->expectNotToPerformAssertions();
Expand Down
5 changes: 2 additions & 3 deletions appdata/modules/FramelixTests/tests/Db/BasicTestMysqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Db;

use Framelix\Framelix\Db\Mysql;
use PHPUnit\Framework\Attributes\Depends;

final class BasicTestMysqlTest extends BasicTestBase
{
Expand Down Expand Up @@ -30,9 +31,7 @@ protected function createTestTable(): void
);
}

/**
* @depends testCleanup
*/
#[Depends("testCleanup")]
public function testExceptionConnectError()
{
$this->assertExceptionOnCall(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Db;

use Framelix\Framelix\Db\Postgres;
use PHPUnit\Framework\Attributes\Depends;

final class BasicTestPostgresTest extends BasicTestBase
{
Expand All @@ -27,9 +28,7 @@ protected function createTestTable(): void
);
}

/**
* @depends testCleanup
*/
#[Depends("testCleanup")]
public function testExceptionConnectError()
{
$this->assertExceptionOnCall(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Db;

use Framelix\Framelix\Db\Sqlite;
use PHPUnit\Framework\Attributes\Depends;

final class BasicTestSqliteTest extends BasicTestBase
{
Expand All @@ -27,9 +28,7 @@ protected function createTestTable(): void
);
}

/**
* @depends testCreate
*/
#[Depends("testCreate")]
public function testExceptionConnectError()
{
$this->assertExceptionOnCall(function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
use Framelix\FramelixTests\StorableException\TestStorableUnsupportedType;
use Framelix\FramelixTests\TestCaseDbTypes;

use PHPUnit\Framework\Attributes\Depends;

use function count;
use function in_array;
use function print_r;
Expand Down Expand Up @@ -43,9 +45,7 @@ public function testBuilderQueries(): void
$this->assertBuilderQueryCount(0, $queries, true);
}

/**
* @depends testBuilderQueries
*/
#[Depends("testBuilderQueries")]
public function testBuilderQueries2(): void
{
$db = Sql::get('test');
Expand All @@ -67,9 +67,7 @@ public function testBuilderQueries2(): void
$this->assertBuilderQueryCount(4, $queries, true);
}

/**
* @depends testBuilderQueries2
*/
#[Depends("testBuilderQueries2")]
public function testBuilderQueries3(): void
{
// previously we have changed 3 columns and dropped one index
Expand Down Expand Up @@ -97,9 +95,7 @@ public function testBuilderQueries3(): void
$db->query('CREATE TABLE ' . $db->quoteIdentifier('unused_table') . ' (`id` INTEGER NULL DEFAULT NULL)');
}

/**
* @depends testBuilderQueries3
*/
#[Depends("testBuilderQueries3")]
public function testBuilderQueries4(): void
{
$db = Sql::get('test');
Expand All @@ -122,9 +118,7 @@ public function testBuilderQueries4(): void
}


/**
* @depends testBuilderQueries3
*/
#[Depends("testBuilderQueries3")]
public function testUnsupportedDbPropertyType(): void
{
$this->assertExceptionOnCall(function () {
Expand All @@ -139,9 +133,7 @@ public function testUnsupportedDbPropertyType(): void
}


/**
* @depends testUnsupportedDbPropertyType
*/
#[Depends("testUnsupportedDbPropertyType")]
public function testNoDbPropertyType(): void
{
$this->assertExceptionOnCall(function () {
Expand Down
47 changes: 13 additions & 34 deletions appdata/modules/FramelixTests/tests/Db/StorableTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
use Framelix\FramelixTests\Storable\TestStorablePrefetch;
use Framelix\FramelixTests\TestCaseDbTypes;

use PHPUnit\Framework\Attributes\Depends;

use function array_chunk;
use function array_keys;
use function array_reverse;
Expand Down Expand Up @@ -216,9 +218,7 @@ public function testStoreAndDelete(): void
}
}

/**
* @depends testStoreAndDelete
*/
#[Depends("testStoreAndDelete")]
public function testFetch(): void
{
// fetch last 50 teststorables1 as they all have the same data applied
Expand Down Expand Up @@ -288,9 +288,7 @@ public function testFetch(): void
$storable->delete(true);
}

/**
* @depends testFetch
*/
#[Depends("testFetch")]
public function testDepthFetch(): void
{
$storables = TestStorable2::getByCondition(
Expand All @@ -299,9 +297,7 @@ public function testDepthFetch(): void
$this->assertGreaterThan(0, count($storables));
}

/**
* @depends testDepthFetch
*/
#[Depends("testDepthFetch")]
public function testUpdate(): void
{
// updateTime does update by default
Expand All @@ -322,9 +318,7 @@ public function testUpdate(): void
$this->assertEquals($upateTime, $storable->updateTime->getTimestamp());
}

/**
* @depends testDepthFetch
*/
#[Depends("testDepthFetch")]
public function testFetchChildsOfAbstractStorables(): void
{
// fetching all from type storable are effectively all that exist
Expand All @@ -344,9 +338,7 @@ public function testFetchChildsOfAbstractStorables(): void
$this->assertSame($chunk, array_keys($storables));
}

/**
* @depends testFetchChildsOfAbstractStorables
*/
#[Depends("testFetchChildsOfAbstractStorables")]
public function testDatatypesSetter(): void
{
$this->dummyValues = [
Expand All @@ -371,9 +363,7 @@ public function testDatatypesSetter(): void
$this->assertStorablePropertyValueSetter($storable, "dateTime", [DateTime::class]);
}

/**
* @depends testDatatypesSetter
*/
#[Depends("testDatatypesSetter")]
public function testDatatypesGetter(): void
{
$storable = TestStorable2::getByConditionOne(
Expand All @@ -394,9 +384,7 @@ public function testDatatypesGetter(): void
$this->assertIsString($storable->getOriginalDbValueForProperty("longTextLazy"));
}

/**
* @depends testDatatypesSetter
*/
#[Depends("testDatatypesSetter")]
public function testDatatypesNoPrefetch(): void
{
$storables = TestStorablePrefetch::getByCondition();
Expand All @@ -410,9 +398,7 @@ public function testDatatypesNoPrefetch(): void
$this->assertExecutedQueries(count($storables));
}

/**
* @depends testDatatypesNoPrefetch
*/
#[Depends("testDatatypesNoPrefetch")]
public function testDatatypesPrefetch(): void
{
$storables = TestStorablePrefetch::getByCondition();
Expand All @@ -431,9 +417,7 @@ public function testDatatypesPrefetch(): void
$this->assertExecutedQueries($requiredPrefetchQueries);
}

/**
* @depends testDatatypesPrefetch
*/
#[Depends("testDatatypesPrefetch")]
public function testDeleteAll(): void
{
// delete with null does nothing
Expand All @@ -443,9 +427,7 @@ public function testDeleteAll(): void
$this->assertCount(0, TestStorable1::getByCondition());
}

/**
* @depends testDeleteAll
*/
#[Depends("testDeleteAll")]
public function testMiscExceptions(): void
{
$this->assertExceptionOnCall(function () {
Expand Down Expand Up @@ -487,10 +469,7 @@ public function testMiscExceptions(): void
}, [], Redirect::class);
}

/**
* Test all framework default storables with generic and specific tests
* @depends testMiscExceptions
*/
#[Depends("testMiscExceptions")]
public function testDefaultStorables(): void
{
$storableFiles = FileUtils::getFiles(
Expand Down
14 changes: 5 additions & 9 deletions appdata/modules/FramelixTests/tests/Html/CompilerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
use Framelix\Framelix\Utils\FileUtils;
use Framelix\FramelixTests\TestCase;

use PHPUnit\Framework\Attributes\Depends;

use function file_get_contents;
use function file_put_contents;
use function unlink;
Expand All @@ -28,9 +30,7 @@ public function testCleanup(): void
$this->assertCount(0, $files);
}

/**
* @depends testCleanup
*/
#[Depends("testCleanup")]
public function testBabel(): void
{
Config::$devMode = false;
Expand All @@ -40,9 +40,7 @@ public function testBabel(): void
Config::$devMode = true;
}

/**
* @depends testBabel
*/
#[Depends("testBabel")]
public function tests(): void
{
$distFolder = __DIR__ . "/../../public/dist";
Expand Down Expand Up @@ -72,9 +70,7 @@ public function tests(): void
);
}

/**
* @depends tests
*/
#[Depends("tests")]
public function testUrls(): void
{
$this->assertInstanceOf(
Expand Down
6 changes: 3 additions & 3 deletions appdata/modules/FramelixTests/tests/Utils/FileUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Framelix\Framelix\Utils\FileUtils;
use Framelix\FramelixTests\TestCase;

use PHPUnit\Framework\Attributes\Depends;

use function basename;
use function dirname;
use function file_put_contents;
Expand Down Expand Up @@ -104,9 +106,7 @@ public function testTmpFolder1(): void
$this->assertCount(1, FileUtils::getFiles($folder));
}

/**
* @depends testTmpFolder1
*/
#[Depends("testTmpFolder1")]
public function testTmpFolder2(): void
{
$this->assertCount(
Expand Down

0 comments on commit b804a1f

Please sign in to comment.