Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<?php
namespace Breyta\Test\Migrations;
use Breyta\Migrations;
use Breyta\Test\TestCase;
use Mockery as m;
class LocatingMigrationsTest extends TestCase
{
protected $pdo;
protected function setUp()
{
parent::setUp();
$this->pdo = m::mock(\PDO::class);
}
/** @test */
public function returnsAStatusObject()
{
$migrations = new Migrations($this->pdo, __DIR__ . '/../Example');
$status = $migrations->getStatus();
self::assertObjectHasAttribute('migrations', $status);
self::assertObjectHasAttribute('count', $status);
}
/** @test */
public function findsMigrationsInTheGivenPath()
{
$migrations = new Migrations($this->pdo, __DIR__ . '/../Example');
$status = $migrations->getStatus();
self::assertContains((object)[
'file' => 'CreateAnimalsTable.php',
'status' => 'new',
], $status->migrations, '', false, false);
}
// /** @test */
// public function findsMigrationsInSubFolders()
// {
// $migrations = new Migrations($this->pdo, __DIR__ . '/../Example');
//
// $status = $migrations->getStatus();
//
// self::assertContains((object)[
// 'file' => 'Grouped/2018-11-22T22-59-59_FooBar.php',
// 'status' => 'new',
// ], $status->migrations, '', false, false);
// }
/** @test */
public function throwsWhenTheFolderDoesNotExist()
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('The path to migrations is not valid');
$migrations = new Migrations(m::mock(\PDO::class), '/any/non-existing/path');
}
/** @test */
public function throwsWhenTheGivenPathIsAFile()
{
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('The path to migrations is not valid');
$migrations = new Migrations(m::mock(\PDO::class), __FILE__);
}
/** @test */
public function throwsWhenTheGivenPathIsASymLinkToAFile()
{
if (file_exists('/tmp/symlink')) {
unlink('/tmp/symlink');
}
if (!@symlink(__FILE__, '/tmp/symlink')) {
$this->markTestSkipped('Could not create a symlink');
return;
}
self::expectException(\InvalidArgumentException::class);
self::expectExceptionMessage('The path to migrations is not valid');
$migrations = new Migrations(m::mock(\PDO::class), '/tmp/symlink');
}
/** @test */
public function allowsSymLinksToADirectory()
{
if (file_exists('/tmp/symlink')) {
unlink('/tmp/symlink');
}
if (!@symlink(__DIR__, '/tmp/symlink')) {
$this->markTestSkipped('Could not create a symlink');
return;
}
$migrations = new Migrations(m::mock(\PDO::class), '/tmp/symlink');
self::assertInstanceOf(Migrations::class, $migrations);
}
}