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

Commit 1d465d9

Browse files
committed
Merge branch 'feature/46' into develop
Close #46
2 parents fd2a1c8 + 6c77e33 commit 1d465d9

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ All notable changes to this project will be documented in this file, in reverse
1313
result of an extract class refactoring, and contain the logic specific to
1414
calcualting the checksum for each ISBN style. `Zend\Validator\Isbn` now
1515
instantiates the appropriate one and invokes it.
16+
- [#46](https://github.com/zendframework/zend-validator/pull/46) updates
17+
`Zend\Validator\Db\AbstractDb` to implement `Zend\Db\Adapter\AdapterAwareInterface`,
18+
by composing `Zend\Db\Adapter\AdapterAwareTrait`.
1619

1720
### Deprecated
1821

src/Db/AbstractDb.php

100644100755
Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
use Traversable;
1313
use Zend\Db\Adapter\Adapter as DbAdapter;
14+
use Zend\Db\Adapter\AdapterAwareInterface;
15+
use Zend\Db\Adapter\AdapterAwareTrait;
1416
use Zend\Db\Sql\Select;
1517
use Zend\Db\Sql\Sql;
1618
use Zend\Db\Sql\TableIdentifier;
@@ -21,8 +23,10 @@
2123
/**
2224
* Class for Database record validation
2325
*/
24-
abstract class AbstractDb extends AbstractValidator
26+
abstract class AbstractDb extends AbstractValidator implements AdapterAwareInterface
2527
{
28+
use AdapterAwareTrait;
29+
2630
/**
2731
* Error constants
2832
*/
@@ -64,13 +68,6 @@ abstract class AbstractDb extends AbstractValidator
6468
*/
6569
protected $exclude = null;
6670

67-
/**
68-
* Database adapter to use. If null isValid() will throw an exception
69-
*
70-
* @var \Zend\Db\Adapter\Adapter
71-
*/
72-
protected $adapter = null;
73-
7471
/**
7572
* Provides basic configuration for use with Zend\Validator\Db Validators
7673
* Setting $exclude allows a single record to be excluded from matching.
@@ -166,8 +163,7 @@ public function getAdapter()
166163
*/
167164
public function setAdapter(DbAdapter $adapter)
168165
{
169-
$this->adapter = $adapter;
170-
return $this;
166+
return $this->setDbAdapter($adapter);
171167
}
172168

173169
/**

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)