Skip to content

Commit

Permalink
Additional tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FaimMedia committed Apr 29, 2024
1 parent 202d03e commit 85f8f6b
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 2 deletions.
23 changes: 21 additions & 2 deletions test/Migration/MigrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use FaimMedia\Migration\Test\AbstractTestCase;

use PDO;

use FaimMedia\Migration\Exception;

/**
Expand All @@ -28,10 +26,31 @@ public function testFullMigration(): void
{
$this->migration->run();

parent::assertSame($this->migrationCount(), 4);

parent::assertTrue(parent::tableExists('test'));
parent::assertTrue(parent::tableExists('test_1'));
parent::assertTrue(parent::tableExists('test_2'));
parent::assertTrue(parent::tableExists('test_3'));
parent::assertTrue(parent::tableExists('test_4'));
parent::assertTrue(parent::tableExists('new_table'));
}

/**
* Test partial migration
*/
public function testVersion1Migration(): void
{
$this->migration->run('0001');

parent::assertSame($this->migrationCount(), 1);

parent::assertTrue(parent::tableExists('test'));

parent::assertFalse(parent::tableExists('test_1'));
parent::assertFalse(parent::tableExists('test_2'));
parent::assertFalse(parent::tableExists('test_3'));
parent::assertFalse(parent::tableExists('test_4'));
parent::assertFalse(parent::tableExists('new_table'));
}
}
61 changes: 61 additions & 0 deletions test/Migration/VersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace FaimMedia\Migration\Test\Migration;

use FaimMedia\Migration\Test\AbstractTestCase;

use FaimMedia\Migration\Exception;

/**
* Test version exceptions
*/
class VersionTest extends AbstractTestCase
{
/**
* Setup
*/
public function setUp(): void
{
parent::setUp();
}

/**
* Test invalid number
*/
public function testExceptionVersionNumber(): void
{
parent::expectException(Exception::class);
parent::expectExceptionCode(Exception::VERSION_NUMBER);

$this->migration->validateVersion(3);
}

/**
* Test non existing path
*/
public function testExceptionNonExistingPath(): void
{
parent::expectException(Exception::class);
parent::expectExceptionCode(Exception::FOLDER_STRUCTURE);

$this->migration->validateVersion('0999');
}

/**
* Full migration test
*/
public function testExceptionEmptyPath(): void
{
parent::expectException(Exception::class);
parent::expectExceptionCode(Exception::FOLDER_EMPTY);

$versionNumber = '0999';
$parentPath = sys_get_temp_dir() . '/' . substr(md5(uniqid()), 0, 10);
$randomPath = $parentPath . '/' . $versionNumber;

mkdir($randomPath, 0775, true);

$this->migration->setPath($parentPath);
$this->migration->validateVersion('0999');
}
}

0 comments on commit 85f8f6b

Please sign in to comment.