mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-07-30 19:50:12 +02:00
PHP7 Adapter
This commit is contained in:
@@ -5,37 +5,26 @@ namespace DesignPatterns\Structural\Adapter\Tests;
|
||||
use DesignPatterns\Structural\Adapter\Book;
|
||||
use DesignPatterns\Structural\Adapter\EBookAdapter;
|
||||
use DesignPatterns\Structural\Adapter\Kindle;
|
||||
use DesignPatterns\Structural\Adapter\PaperBookInterface;
|
||||
|
||||
/**
|
||||
* AdapterTest shows the use of an adapted e-book that behave like a book
|
||||
* You don't have to change the code of your client.
|
||||
*/
|
||||
class AdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getBook()
|
||||
public function testCanTurnPageOnBook()
|
||||
{
|
||||
return array(
|
||||
array(new Book()),
|
||||
// we build a "wrapped" electronic book in the adapter
|
||||
array(new EBookAdapter(new Kindle())),
|
||||
);
|
||||
$book = new Book();
|
||||
$book->open();
|
||||
$book->turnPage();
|
||||
|
||||
$this->assertEquals(2, $book->getPage());
|
||||
}
|
||||
|
||||
/**
|
||||
* This client only knows paper book but surprise, surprise, the second book
|
||||
* is in fact an electronic book, but both work the same way.
|
||||
*
|
||||
* @param PaperBookInterface $book
|
||||
*
|
||||
* @dataProvider getBook
|
||||
*/
|
||||
public function testIAmAnOldClient(PaperBookInterface $book)
|
||||
public function testCanTurnPageOnKindleLikeInANormalBook()
|
||||
{
|
||||
$this->assertTrue(method_exists($book, 'open'));
|
||||
$this->assertTrue(method_exists($book, 'turnPage'));
|
||||
$kindle = new Kindle();
|
||||
$book = new EBookAdapter($kindle);
|
||||
|
||||
$book->open();
|
||||
$book->turnPage();
|
||||
|
||||
$this->assertEquals(2, $book->getPage());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user