Replaced with strict assertions

This commit is contained in:
Samuel NELA
2018-09-29 16:27:02 +02:00
parent e68d7b213e
commit 16d6f8740d
17 changed files with 36 additions and 36 deletions

View File

@@ -33,7 +33,7 @@ class ChainTest extends TestCase
->willReturn('GET');
$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()
@@ -47,6 +47,6 @@ class ChainTest extends TestCase
->willReturn('GET');
$request->method('getUri')->willReturn($uri);
$this->assertEquals('Hello World!', $this->chain->handle($request));
$this->assertSame('Hello World!', $this->chain->handle($request));
}
}

View File

@@ -16,6 +16,6 @@ class CommandTest extends TestCase
$invoker->setCommand(new HelloCommand($receiver));
$invoker->run();
$this->assertEquals('Hello World', $receiver->getOutput());
$this->assertSame('Hello World', $receiver->getOutput());
}
}

View File

@@ -17,17 +17,17 @@ class UndoableCommandTest extends TestCase
$invoker->setCommand(new HelloCommand($receiver));
$invoker->run();
$this->assertEquals('Hello World', $receiver->getOutput());
$this->assertSame('Hello World', $receiver->getOutput());
$messageDateCommand = new AddMessageDateCommand($receiver);
$messageDateCommand->execute();
$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();
$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());
}
}

View File

@@ -23,7 +23,7 @@ class IteratorTest extends TestCase
$books[] = $book->getAuthorAndTitle();
}
$this->assertEquals(
$this->assertSame(
[
'Learning PHP Design Patterns by William Sanders',
'Professional Php Design Patterns by Aaron Saray',
@@ -48,7 +48,7 @@ class IteratorTest extends TestCase
$books[] = $book->getAuthorAndTitle();
}
$this->assertEquals(
$this->assertSame(
['Professional Php Design Patterns by Aaron Saray'],
$books
);

View File

@@ -15,18 +15,18 @@ class MementoTest extends TestCase
// open the ticket
$ticket->open();
$openedState = $ticket->getState();
$this->assertEquals(State::STATE_OPENED, (string) $ticket->getState());
$this->assertSame(State::STATE_OPENED, (string) $ticket->getState());
$memento = $ticket->saveToMemento();
// assign the ticket
$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
$ticket->restoreFromMemento($memento);
$this->assertEquals(State::STATE_OPENED, (string) $ticket->getState());
$this->assertSame(State::STATE_OPENED, (string) $ticket->getState());
$this->assertNotSame($openedState, $ticket->getState());
}
}

View File

@@ -11,7 +11,7 @@ class StateTest extends TestCase
{
$orderContext = OrderContext::create();
$this->assertEquals('created', $orderContext->toString());
$this->assertSame('created', $orderContext->toString());
}
public function testCanProceedToStateShipped()
@@ -19,7 +19,7 @@ class StateTest extends TestCase
$contextOrder = OrderContext::create();
$contextOrder->proceedToNext();
$this->assertEquals('shipped', $contextOrder->toString());
$this->assertSame('shipped', $contextOrder->toString());
}
public function testCanProceedToStateDone()
@@ -28,7 +28,7 @@ class StateTest extends TestCase
$contextOrder->proceedToNext();
$contextOrder->proceedToNext();
$this->assertEquals('done', $contextOrder->toString());
$this->assertSame('done', $contextOrder->toString());
}
public function testStateDoneIsTheLastPossibleState()
@@ -38,6 +38,6 @@ class StateTest extends TestCase
$contextOrder->proceedToNext();
$contextOrder->proceedToNext();
$this->assertEquals('done', $contextOrder->toString());
$this->assertSame('done', $contextOrder->toString());
}
}

View File

@@ -49,7 +49,7 @@ class StrategyTest extends TestCase
$elements = $obj->executeStrategy($collection);
$firstElement = array_shift($elements);
$this->assertEquals($expected, $firstElement);
$this->assertSame($expected, $firstElement);
}
/**
@@ -64,6 +64,6 @@ class StrategyTest extends TestCase
$elements = $obj->executeStrategy($collection);
$firstElement = array_shift($elements);
$this->assertEquals($expected, $firstElement);
$this->assertSame($expected, $firstElement);
}
}

View File

@@ -12,7 +12,7 @@ class JourneyTest extends TestCase
$beachJourney = new TemplateMethod\BeachJourney();
$beachJourney->takeATrip();
$this->assertEquals(
$this->assertSame(
['Buy a flight ticket', 'Taking the plane', 'Swimming and sun-bathing', 'Taking the plane'],
$beachJourney->getThingsToDo()
);
@@ -23,7 +23,7 @@ class JourneyTest extends TestCase
$beachJourney = new TemplateMethod\CityJourney();
$beachJourney->takeATrip();
$this->assertEquals(
$this->assertSame(
[
'Buy a flight ticket',
'Taking the plane',

View File

@@ -15,7 +15,7 @@ class AdapterTest extends TestCase
$book->open();
$book->turnPage();
$this->assertEquals(2, $book->getPage());
$this->assertSame(2, $book->getPage());
}
public function testCanTurnPageOnKindleLikeInANormalBook()
@@ -26,6 +26,6 @@ class AdapterTest extends TestCase
$book->open();
$book->turnPage();
$this->assertEquals(2, $book->getPage());
$this->assertSame(2, $book->getPage());
}
}

View File

@@ -12,10 +12,10 @@ class BridgeTest extends TestCase
public function testCanPrintUsingThePlainTextPrinter()
{
$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
$service->setImplementation(new HtmlFormatter());
$this->assertEquals('<p>Hello World</p>', $service->get());
$this->assertSame('<p>Hello World</p>', $service->get());
}
}

View File

@@ -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
// currently support nested forms
$this->assertEquals(
$this->assertSame(
'<form>Email:<input type="text" /><form>Password:<input type="text" /></form></form>',
$form->render()
);

View File

@@ -13,8 +13,8 @@ class DecoratorTest extends TestCase
{
$booking = new DoubleRoomBooking();
$this->assertEquals(40, $booking->calculatePrice());
$this->assertEquals('double room', $booking->getDescription());
$this->assertSame(40, $booking->calculatePrice());
$this->assertSame('double room', $booking->getDescription());
}
public function testCanCalculatePriceForDoubleRoomBookingWithWiFi()
@@ -22,8 +22,8 @@ class DecoratorTest extends TestCase
$booking = new DoubleRoomBooking();
$booking = new WiFi($booking);
$this->assertEquals(42, $booking->calculatePrice());
$this->assertEquals('double room with wifi', $booking->getDescription());
$this->assertSame(42, $booking->calculatePrice());
$this->assertSame('double room with wifi', $booking->getDescription());
}
public function testCanCalculatePriceForDoubleRoomBookingWithWiFiAndExtraBed()
@@ -32,7 +32,7 @@ class DecoratorTest extends TestCase
$booking = new WiFi($booking);
$booking = new ExtraBed($booking);
$this->assertEquals(72, $booking->calculatePrice());
$this->assertEquals('double room with wifi with extra bed', $booking->getDescription());
$this->assertSame(72, $booking->calculatePrice());
$this->assertSame('double room with wifi with extra bed', $booking->getDescription());
}
}

View File

@@ -13,6 +13,6 @@ class DependencyInjectionTest extends TestCase
$config = new DatabaseConfiguration('localhost', 3306, 'domnikl', '1234');
$connection = new DatabaseConnection($config);
$this->assertEquals('domnikl:1234@localhost:3306', $connection->getDsn());
$this->assertSame('domnikl:1234@localhost:3306', $connection->getDsn());
}
}

View File

@@ -31,6 +31,6 @@ class FacadeTest extends TestCase
$facade->turnOn();
// but you can also access the underlying components
$this->assertEquals('Linux', $os->getName());
$this->assertSame('Linux', $os->getName());
}
}

View File

@@ -14,6 +14,6 @@ class FluentInterfaceTest extends TestCase
->from('foobar', 'f')
->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);
}
}

View File

@@ -20,7 +20,7 @@ class FlyweightTest extends TestCase
$flyweight = $factory->get($char);
$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);
}
}

View File

@@ -13,12 +13,12 @@ class ProxyTest extends TestCase
$bankAccount->deposit(30);
// 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
$bankAccount->deposit(50);
// this time the previously calculated balance is returned again without re-calculating it
$this->assertEquals(30, $bankAccount->getBalance());
$this->assertSame(30, $bankAccount->getBalance());
}
}