This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
#!/bin/sh | |
curl -s https://getcomposer.org/installer | php | |
php composer.phar create-project isidromerayo/simple_php_skeleton --dev | |
cd simple_php_skeleton | |
bin/phpunit |
<?php | |
/** | |
* @expectedException OutOfBoundsException | |
*/ | |
public function testThrowsException() | |
{ | |
$mock = m::mock('MyMockedClass'); | |
$mock->shouldReceive('foo')->andThrow(new OutOfBoundsException); | |
$mock->foo(); |
<?php | |
/** | |
* @expectedException RuntimeException | |
*/ | |
public function testThrowExceptionStub() | |
{ | |
$stub = $this->getMock('SomeClass'); | |
$stub->expects($this->any()) |
<?php | |
public function testProcessSomeDataLogsExceptions() { | |
$logger = Phake::mock('LOGGER'); | |
$data = Phake::mock('MyData'); | |
$processor = Phake::mock('MyDataProcessor'); | |
Phake::when($processor)->process($data) | |
->thenThrow(new Exception('My error message!')); |
<?php | |
/** | |
* @test | |
*/ | |
public function getsAverageTemperatureFromThreeServiceReadings() { | |
$service = m::mock('Service'); | |
$service->shouldReceive('readTemp')->times(3)->andReturn(10, 12, 14); | |
$temperature = new Temperature($service); | |
$this->assertEquals(12, $temperature->average()); |
@Test | |
public void onBarcode_search_catalog() throws Exception { | |
Catalog catalog = mock(Catalog.class); | |
Screen screen = mock(Screen.class); | |
PointOfSale pointOfSale = new PointOfSale(catalog, screen); | |
pointOfSale.onBarcode("123"); | |
verify(catalog).search("123"); | |
} |
@Test | |
public void onBarcode_search_catalog() throws Exception { | |
Catalog catalog = mock(Catalog.class); | |
PointOfSale pointOfSale = new PointOfSale(catalog); | |
pointOfSale.onBarcode("123"); | |
verify(catalog).search("123"); | |
} |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer