mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-08-02 05:00:15 +02:00
Replaced with strict assertions
This commit is contained in:
@@ -33,7 +33,7 @@ class ChainTest extends TestCase
|
|||||||
->willReturn('GET');
|
->willReturn('GET');
|
||||||
$request->method('getUri')->willReturn($uri);
|
$request->method('getUri')->willReturn($uri);
|
||||||
|
|
||||||
$this->assertEquals('Hello In Memory!', $this->chain->handle($request));
|
$this->assertSame('Hello In Memory!', $this->chain->handle($request));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanRequestKeyInSlowStorage()
|
public function testCanRequestKeyInSlowStorage()
|
||||||
@@ -47,6 +47,6 @@ class ChainTest extends TestCase
|
|||||||
->willReturn('GET');
|
->willReturn('GET');
|
||||||
$request->method('getUri')->willReturn($uri);
|
$request->method('getUri')->willReturn($uri);
|
||||||
|
|
||||||
$this->assertEquals('Hello World!', $this->chain->handle($request));
|
$this->assertSame('Hello World!', $this->chain->handle($request));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,6 +16,6 @@ class CommandTest extends TestCase
|
|||||||
|
|
||||||
$invoker->setCommand(new HelloCommand($receiver));
|
$invoker->setCommand(new HelloCommand($receiver));
|
||||||
$invoker->run();
|
$invoker->run();
|
||||||
$this->assertEquals('Hello World', $receiver->getOutput());
|
$this->assertSame('Hello World', $receiver->getOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -17,17 +17,17 @@ class UndoableCommandTest extends TestCase
|
|||||||
|
|
||||||
$invoker->setCommand(new HelloCommand($receiver));
|
$invoker->setCommand(new HelloCommand($receiver));
|
||||||
$invoker->run();
|
$invoker->run();
|
||||||
$this->assertEquals('Hello World', $receiver->getOutput());
|
$this->assertSame('Hello World', $receiver->getOutput());
|
||||||
|
|
||||||
$messageDateCommand = new AddMessageDateCommand($receiver);
|
$messageDateCommand = new AddMessageDateCommand($receiver);
|
||||||
$messageDateCommand->execute();
|
$messageDateCommand->execute();
|
||||||
|
|
||||||
$invoker->run();
|
$invoker->run();
|
||||||
$this->assertEquals("Hello World\nHello World [".date('Y-m-d').']', $receiver->getOutput());
|
$this->assertSame("Hello World\nHello World [".date('Y-m-d').']', $receiver->getOutput());
|
||||||
|
|
||||||
$messageDateCommand->undo();
|
$messageDateCommand->undo();
|
||||||
|
|
||||||
$invoker->run();
|
$invoker->run();
|
||||||
$this->assertEquals("Hello World\nHello World [".date('Y-m-d')."]\nHello World", $receiver->getOutput());
|
$this->assertSame("Hello World\nHello World [".date('Y-m-d')."]\nHello World", $receiver->getOutput());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -23,7 +23,7 @@ class IteratorTest extends TestCase
|
|||||||
$books[] = $book->getAuthorAndTitle();
|
$books[] = $book->getAuthorAndTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
[
|
[
|
||||||
'Learning PHP Design Patterns by William Sanders',
|
'Learning PHP Design Patterns by William Sanders',
|
||||||
'Professional Php Design Patterns by Aaron Saray',
|
'Professional Php Design Patterns by Aaron Saray',
|
||||||
@@ -48,7 +48,7 @@ class IteratorTest extends TestCase
|
|||||||
$books[] = $book->getAuthorAndTitle();
|
$books[] = $book->getAuthorAndTitle();
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
['Professional Php Design Patterns by Aaron Saray'],
|
['Professional Php Design Patterns by Aaron Saray'],
|
||||||
$books
|
$books
|
||||||
);
|
);
|
||||||
|
@@ -15,18 +15,18 @@ class MementoTest extends TestCase
|
|||||||
// open the ticket
|
// open the ticket
|
||||||
$ticket->open();
|
$ticket->open();
|
||||||
$openedState = $ticket->getState();
|
$openedState = $ticket->getState();
|
||||||
$this->assertEquals(State::STATE_OPENED, (string) $ticket->getState());
|
$this->assertSame(State::STATE_OPENED, (string) $ticket->getState());
|
||||||
|
|
||||||
$memento = $ticket->saveToMemento();
|
$memento = $ticket->saveToMemento();
|
||||||
|
|
||||||
// assign the ticket
|
// assign the ticket
|
||||||
$ticket->assign();
|
$ticket->assign();
|
||||||
$this->assertEquals(State::STATE_ASSIGNED, (string) $ticket->getState());
|
$this->assertSame(State::STATE_ASSIGNED, (string) $ticket->getState());
|
||||||
|
|
||||||
// now restore to the opened state, but verify that the state object has been cloned for the memento
|
// now restore to the opened state, but verify that the state object has been cloned for the memento
|
||||||
$ticket->restoreFromMemento($memento);
|
$ticket->restoreFromMemento($memento);
|
||||||
|
|
||||||
$this->assertEquals(State::STATE_OPENED, (string) $ticket->getState());
|
$this->assertSame(State::STATE_OPENED, (string) $ticket->getState());
|
||||||
$this->assertNotSame($openedState, $ticket->getState());
|
$this->assertNotSame($openedState, $ticket->getState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,7 +11,7 @@ class StateTest extends TestCase
|
|||||||
{
|
{
|
||||||
$orderContext = OrderContext::create();
|
$orderContext = OrderContext::create();
|
||||||
|
|
||||||
$this->assertEquals('created', $orderContext->toString());
|
$this->assertSame('created', $orderContext->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanProceedToStateShipped()
|
public function testCanProceedToStateShipped()
|
||||||
@@ -19,7 +19,7 @@ class StateTest extends TestCase
|
|||||||
$contextOrder = OrderContext::create();
|
$contextOrder = OrderContext::create();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
|
|
||||||
$this->assertEquals('shipped', $contextOrder->toString());
|
$this->assertSame('shipped', $contextOrder->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanProceedToStateDone()
|
public function testCanProceedToStateDone()
|
||||||
@@ -28,7 +28,7 @@ class StateTest extends TestCase
|
|||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
|
|
||||||
$this->assertEquals('done', $contextOrder->toString());
|
$this->assertSame('done', $contextOrder->toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testStateDoneIsTheLastPossibleState()
|
public function testStateDoneIsTheLastPossibleState()
|
||||||
@@ -38,6 +38,6 @@ class StateTest extends TestCase
|
|||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
$contextOrder->proceedToNext();
|
$contextOrder->proceedToNext();
|
||||||
|
|
||||||
$this->assertEquals('done', $contextOrder->toString());
|
$this->assertSame('done', $contextOrder->toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -49,7 +49,7 @@ class StrategyTest extends TestCase
|
|||||||
$elements = $obj->executeStrategy($collection);
|
$elements = $obj->executeStrategy($collection);
|
||||||
|
|
||||||
$firstElement = array_shift($elements);
|
$firstElement = array_shift($elements);
|
||||||
$this->assertEquals($expected, $firstElement);
|
$this->assertSame($expected, $firstElement);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,6 +64,6 @@ class StrategyTest extends TestCase
|
|||||||
$elements = $obj->executeStrategy($collection);
|
$elements = $obj->executeStrategy($collection);
|
||||||
|
|
||||||
$firstElement = array_shift($elements);
|
$firstElement = array_shift($elements);
|
||||||
$this->assertEquals($expected, $firstElement);
|
$this->assertSame($expected, $firstElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ class JourneyTest extends TestCase
|
|||||||
$beachJourney = new TemplateMethod\BeachJourney();
|
$beachJourney = new TemplateMethod\BeachJourney();
|
||||||
$beachJourney->takeATrip();
|
$beachJourney->takeATrip();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
['Buy a flight ticket', 'Taking the plane', 'Swimming and sun-bathing', 'Taking the plane'],
|
['Buy a flight ticket', 'Taking the plane', 'Swimming and sun-bathing', 'Taking the plane'],
|
||||||
$beachJourney->getThingsToDo()
|
$beachJourney->getThingsToDo()
|
||||||
);
|
);
|
||||||
@@ -23,7 +23,7 @@ class JourneyTest extends TestCase
|
|||||||
$beachJourney = new TemplateMethod\CityJourney();
|
$beachJourney = new TemplateMethod\CityJourney();
|
||||||
$beachJourney->takeATrip();
|
$beachJourney->takeATrip();
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
[
|
[
|
||||||
'Buy a flight ticket',
|
'Buy a flight ticket',
|
||||||
'Taking the plane',
|
'Taking the plane',
|
||||||
|
@@ -15,7 +15,7 @@ class AdapterTest extends TestCase
|
|||||||
$book->open();
|
$book->open();
|
||||||
$book->turnPage();
|
$book->turnPage();
|
||||||
|
|
||||||
$this->assertEquals(2, $book->getPage());
|
$this->assertSame(2, $book->getPage());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanTurnPageOnKindleLikeInANormalBook()
|
public function testCanTurnPageOnKindleLikeInANormalBook()
|
||||||
@@ -26,6 +26,6 @@ class AdapterTest extends TestCase
|
|||||||
$book->open();
|
$book->open();
|
||||||
$book->turnPage();
|
$book->turnPage();
|
||||||
|
|
||||||
$this->assertEquals(2, $book->getPage());
|
$this->assertSame(2, $book->getPage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -12,10 +12,10 @@ class BridgeTest extends TestCase
|
|||||||
public function testCanPrintUsingThePlainTextPrinter()
|
public function testCanPrintUsingThePlainTextPrinter()
|
||||||
{
|
{
|
||||||
$service = new HelloWorldService(new PlainTextFormatter());
|
$service = new HelloWorldService(new PlainTextFormatter());
|
||||||
$this->assertEquals('Hello World', $service->get());
|
$this->assertSame('Hello World', $service->get());
|
||||||
|
|
||||||
// now change the implementation and use the HtmlFormatter instead
|
// now change the implementation and use the HtmlFormatter instead
|
||||||
$service->setImplementation(new HtmlFormatter());
|
$service->setImplementation(new HtmlFormatter());
|
||||||
$this->assertEquals('<p>Hello World</p>', $service->get());
|
$this->assertSame('<p>Hello World</p>', $service->get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ class CompositeTest extends TestCase
|
|||||||
// This is just an example, in a real world scenario it is important to remember that web browsers do not
|
// This is just an example, in a real world scenario it is important to remember that web browsers do not
|
||||||
// currently support nested forms
|
// currently support nested forms
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertSame(
|
||||||
'<form>Email:<input type="text" /><form>Password:<input type="text" /></form></form>',
|
'<form>Email:<input type="text" /><form>Password:<input type="text" /></form></form>',
|
||||||
$form->render()
|
$form->render()
|
||||||
);
|
);
|
||||||
|
@@ -13,8 +13,8 @@ class DecoratorTest extends TestCase
|
|||||||
{
|
{
|
||||||
$booking = new DoubleRoomBooking();
|
$booking = new DoubleRoomBooking();
|
||||||
|
|
||||||
$this->assertEquals(40, $booking->calculatePrice());
|
$this->assertSame(40, $booking->calculatePrice());
|
||||||
$this->assertEquals('double room', $booking->getDescription());
|
$this->assertSame('double room', $booking->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanCalculatePriceForDoubleRoomBookingWithWiFi()
|
public function testCanCalculatePriceForDoubleRoomBookingWithWiFi()
|
||||||
@@ -22,8 +22,8 @@ class DecoratorTest extends TestCase
|
|||||||
$booking = new DoubleRoomBooking();
|
$booking = new DoubleRoomBooking();
|
||||||
$booking = new WiFi($booking);
|
$booking = new WiFi($booking);
|
||||||
|
|
||||||
$this->assertEquals(42, $booking->calculatePrice());
|
$this->assertSame(42, $booking->calculatePrice());
|
||||||
$this->assertEquals('double room with wifi', $booking->getDescription());
|
$this->assertSame('double room with wifi', $booking->getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCanCalculatePriceForDoubleRoomBookingWithWiFiAndExtraBed()
|
public function testCanCalculatePriceForDoubleRoomBookingWithWiFiAndExtraBed()
|
||||||
@@ -32,7 +32,7 @@ class DecoratorTest extends TestCase
|
|||||||
$booking = new WiFi($booking);
|
$booking = new WiFi($booking);
|
||||||
$booking = new ExtraBed($booking);
|
$booking = new ExtraBed($booking);
|
||||||
|
|
||||||
$this->assertEquals(72, $booking->calculatePrice());
|
$this->assertSame(72, $booking->calculatePrice());
|
||||||
$this->assertEquals('double room with wifi with extra bed', $booking->getDescription());
|
$this->assertSame('double room with wifi with extra bed', $booking->getDescription());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -13,6 +13,6 @@ class DependencyInjectionTest extends TestCase
|
|||||||
$config = new DatabaseConfiguration('localhost', 3306, 'domnikl', '1234');
|
$config = new DatabaseConfiguration('localhost', 3306, 'domnikl', '1234');
|
||||||
$connection = new DatabaseConnection($config);
|
$connection = new DatabaseConnection($config);
|
||||||
|
|
||||||
$this->assertEquals('domnikl:1234@localhost:3306', $connection->getDsn());
|
$this->assertSame('domnikl:1234@localhost:3306', $connection->getDsn());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,6 @@ class FacadeTest extends TestCase
|
|||||||
$facade->turnOn();
|
$facade->turnOn();
|
||||||
|
|
||||||
// but you can also access the underlying components
|
// but you can also access the underlying components
|
||||||
$this->assertEquals('Linux', $os->getName());
|
$this->assertSame('Linux', $os->getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -14,6 +14,6 @@ class FluentInterfaceTest extends TestCase
|
|||||||
->from('foobar', 'f')
|
->from('foobar', 'f')
|
||||||
->where('f.bar = ?');
|
->where('f.bar = ?');
|
||||||
|
|
||||||
$this->assertEquals('SELECT foo, bar FROM foobar AS f WHERE f.bar = ?', (string) $query);
|
$this->assertSame('SELECT foo, bar FROM foobar AS f WHERE f.bar = ?', (string) $query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -20,7 +20,7 @@ class FlyweightTest extends TestCase
|
|||||||
$flyweight = $factory->get($char);
|
$flyweight = $factory->get($char);
|
||||||
$rendered = $flyweight->render($font);
|
$rendered = $flyweight->render($font);
|
||||||
|
|
||||||
$this->assertEquals(sprintf('Character %s with font %s', $char, $font), $rendered);
|
$this->assertSame(sprintf('Character %s with font %s', $char, $font), $rendered);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -13,12 +13,12 @@ class ProxyTest extends TestCase
|
|||||||
$bankAccount->deposit(30);
|
$bankAccount->deposit(30);
|
||||||
|
|
||||||
// this time balance is being calculated
|
// this time balance is being calculated
|
||||||
$this->assertEquals(30, $bankAccount->getBalance());
|
$this->assertSame(30, $bankAccount->getBalance());
|
||||||
|
|
||||||
// inheritance allows for BankAccountProxy to behave to an outsider exactly like ServerBankAccount
|
// inheritance allows for BankAccountProxy to behave to an outsider exactly like ServerBankAccount
|
||||||
$bankAccount->deposit(50);
|
$bankAccount->deposit(50);
|
||||||
|
|
||||||
// this time the previously calculated balance is returned again without re-calculating it
|
// this time the previously calculated balance is returned again without re-calculating it
|
||||||
$this->assertEquals(30, $bankAccount->getBalance());
|
$this->assertSame(30, $bankAccount->getBalance());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user