/
AdapterFactoryTest.php
111 lines (90 loc) · 3.27 KB
/
AdapterFactoryTest.php
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
110
111
<?php
namespace Test\Phinx\Db\Adapter;
use Phinx\Db\Adapter\AdapterFactory;
class AdapterFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Phinx\Db\Adapter\AdapterFactory
*/
private $factory;
public function setUp()
{
$this->factory = AdapterFactory::instance();
}
public function tearDown()
{
unset($this->factory);
}
public function testInstanceIsFactory()
{
$this->assertInstanceOf('Phinx\Db\Adapter\AdapterFactory', $this->factory);
}
public function testRegisterAdapter()
{
// AdapterFactory::getClass is protected, work around it to avoid
// creating unnecessary instances and making the test more complex.
$method = new \ReflectionMethod(get_class($this->factory), 'getClass');
$method->setAccessible(true);
$adapter = $method->invoke($this->factory, 'mysql');
$this->factory->registerAdapter('test', $adapter);
$this->assertEquals($adapter, $method->invoke($this->factory, 'test'));
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Adapter class "Test\Phinx\Db\Adapter\AdapterFactoryTest" must implement Phinx\Db\Adapter\AdapterInterface
*/
public function testRegisterAdapterFailure()
{
$adapter = get_class($this);
$this->factory->registerAdapter('test', $adapter);
}
public function testGetAdapter()
{
$adapter = $this->factory->getAdapter('mysql', array());
$this->assertInstanceOf('Phinx\Db\Adapter\MysqlAdapter', $adapter);
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Adapter "bad" has not been registered
*/
public function testGetAdapterFailure()
{
$this->factory->getAdapter('bad', array());
}
public function testRegisterWrapper()
{
// WrapperFactory::getClass is protected, work around it to avoid
// creating unnecessary instances and making the test more complex.
$method = new \ReflectionMethod(get_class($this->factory), 'getWrapperClass');
$method->setAccessible(true);
$wrapper = $method->invoke($this->factory, 'proxy');
$this->factory->registerWrapper('test', $wrapper);
$this->assertEquals($wrapper, $method->invoke($this->factory, 'test'));
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Wrapper class "Test\Phinx\Db\Adapter\AdapterFactoryTest" must be implement Phinx\Db\Adapter\WrapperInterface
*/
public function testRegisterWrapperFailure()
{
$wrapper = get_class($this);
$this->factory->registerWrapper('test', $wrapper);
}
private function getAdapterMock()
{
return $this->getMock('Phinx\Db\Adapter\AdapterInterface', array());
}
public function testGetWrapper()
{
$wrapper = $this->factory->getWrapper('prefix', $this->getAdapterMock());
$this->assertInstanceOf('Phinx\Db\Adapter\TablePrefixAdapter', $wrapper);
}
/**
* @expectedException \RuntimeException
* @expectedExceptionMessage Wrapper "nope" has not been registered
*/
public function testGetWrapperFailure()
{
$this->factory->getWrapper('nope', $this->getAdapterMock());
}
}