|
5 | 5 | use DesignPatterns\Structural\Adapter\Book;
|
6 | 6 | use DesignPatterns\Structural\Adapter\EBookAdapter;
|
7 | 7 | use DesignPatterns\Structural\Adapter\Kindle;
|
8 |
| -use DesignPatterns\Structural\Adapter\PaperBookInterface; |
9 | 8 |
|
10 |
| -/** |
11 |
| - * AdapterTest shows the use of an adapted e-book that behave like a book |
12 |
| - * You don't have to change the code of your client. |
13 |
| - */ |
14 | 9 | class AdapterTest extends \PHPUnit_Framework_TestCase
|
15 | 10 | {
|
16 |
| - /** |
17 |
| - * @return array |
18 |
| - */ |
19 |
| - public function getBook() |
| 11 | + public function testCanTurnPageOnBook() |
20 | 12 | {
|
21 |
| - return array( |
22 |
| - array(new Book()), |
23 |
| - // we build a "wrapped" electronic book in the adapter |
24 |
| - array(new EBookAdapter(new Kindle())), |
25 |
| - ); |
| 13 | + $book = new Book(); |
| 14 | + $book->open(); |
| 15 | + $book->turnPage(); |
| 16 | + |
| 17 | + $this->assertEquals(2, $book->getPage()); |
26 | 18 | }
|
27 | 19 |
|
28 |
| - /** |
29 |
| - * This client only knows paper book but surprise, surprise, the second book |
30 |
| - * is in fact an electronic book, but both work the same way. |
31 |
| - * |
32 |
| - * @param PaperBookInterface $book |
33 |
| - * |
34 |
| - * @dataProvider getBook |
35 |
| - */ |
36 |
| - public function testIAmAnOldClient(PaperBookInterface $book) |
| 20 | + public function testCanTurnPageOnKindleLikeInANormalBook() |
37 | 21 | {
|
38 |
| - $this->assertTrue(method_exists($book, 'open')); |
39 |
| - $this->assertTrue(method_exists($book, 'turnPage')); |
| 22 | + $kindle = new Kindle(); |
| 23 | + $book = new EBookAdapter($kindle); |
| 24 | + |
| 25 | + $book->open(); |
| 26 | + $book->turnPage(); |
| 27 | + |
| 28 | + $this->assertEquals(2, $book->getPage()); |
40 | 29 | }
|
41 | 30 | }
|
0 commit comments