Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit 4744b64

Browse files
committed
Added tests for #46
Added tests to number 46 to verify behavior, and updated `AbstractDb` to implement `AdapterAwareInterface`, which was the point of composing the trait in the first place.
1 parent 1f1aa89 commit 4744b64

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

src/Db/AbstractDb.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
use Traversable;
1313
use Zend\Db\Adapter\Adapter as DbAdapter;
14+
use Zend\Db\Adapter\AdapterAwareInterface;
1415
use Zend\Db\Adapter\AdapterAwareTrait;
1516
use Zend\Db\Sql\Select;
1617
use Zend\Db\Sql\Sql;
@@ -22,7 +23,7 @@
2223
/**
2324
* Class for Database record validation
2425
*/
25-
abstract class AbstractDb extends AbstractValidator
26+
abstract class AbstractDb extends AbstractValidator implements AdapterAwareInterface
2627
{
2728
use AdapterAwareTrait;
2829

test/Db/AbstractDbTest.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
namespace ZendTest\Validator\Db;
1111

1212
use ZendTest\Validator\Db\TestAsset\ConcreteDbValidator;
13+
use Zend\Db\Adapter\AdapterAwareInterface;
14+
use Zend\Db\Adapter\Adapter;
1315
use Zend\Db\Sql\Select;
1416

1517
/**
@@ -31,17 +33,21 @@ public function setUp()
3133

3234
public function testConstructorWithNoTableAndSchemaKey()
3335
{
34-
$this->setExpectedException('Zend\Validator\Exception\InvalidArgumentException',
35-
'Table or Schema option missing!');
36+
$this->setExpectedException(
37+
'Zend\Validator\Exception\InvalidArgumentException',
38+
'Table or Schema option missing!'
39+
);
3640
$this->validator = new ConcreteDbValidator([
3741
'field' => 'field',
3842
]);
3943
}
4044

4145
public function testConstructorWithNoFieldKey()
4246
{
43-
$this->setExpectedException('Zend\Validator\Exception\InvalidArgumentException',
44-
'Field option missing!');
47+
$this->setExpectedException(
48+
'Zend\Validator\Exception\InvalidArgumentException',
49+
'Field option missing!'
50+
);
4551
$validator = new ConcreteDbValidator([
4652
'schema' => 'schema',
4753
'table' => 'table',
@@ -87,4 +93,27 @@ public function testGetExclude()
8793

8894
$this->assertEquals($field, $this->validator->getField());
8995
}
96+
97+
/**
98+
* @group #46
99+
*/
100+
public function testImplementationsAreDbAdapterAware()
101+
{
102+
$this->assertInstanceOf(AdapterAwareInterface::class, $this->validator);
103+
}
104+
105+
/**
106+
* @group #46
107+
*/
108+
public function testSetAdapterIsEquivalentToSetDbAdapter()
109+
{
110+
$adapterFirst = $this->prophesize(Adapter::class)->reveal();
111+
$adapterSecond = $this->prophesize(Adapter::class)->reveal();
112+
113+
$this->validator->setAdapter($adapterFirst);
114+
$this->assertAttributeSame($adapterFirst, 'adapter', $this->validator);
115+
116+
$this->validator->setDbAdapter($adapterSecond);
117+
$this->assertAttributeSame($adapterSecond, 'adapter', $this->validator);
118+
}
90119
}

0 commit comments

Comments
 (0)