Skip to content

Instantly share code, notes, and snippets.

#!/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
@isidromerayo
isidromerayo / ExceptionsTest.php
Created February 6, 2012 18:30
Mockery examples
<?php
/**
* @expectedException OutOfBoundsException
*/
public function testThrowsException()
{
$mock = m::mock('MyMockedClass');
$mock->shouldReceive('foo')->andThrow(new OutOfBoundsException);
$mock->foo();
@isidromerayo
isidromerayo / ExceptionsTest.php
Created February 6, 2012 18:25
PHPUnit Mock examples
<?php
/**
* @expectedException RuntimeException
*/
public function testThrowExceptionStub()
{
$stub = $this->getMock('SomeClass');
$stub->expects($this->any())
@isidromerayo
isidromerayo / ExceptionsTest.php
Created February 6, 2012 18:22
Phake examples
<?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!'));
@isidromerayo
isidromerayo / TemperatureTest_Mockery.php
Created February 6, 2012 18:13
Example temperature webservice
<?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());
@isidromerayo
isidromerayo / PointOfSale2Test.java
Created January 24, 2012 18:06
Second test with Mockito - Point Of Sale - Hola TDD
@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");
}
@isidromerayo
isidromerayo / PointOfSaleTest.java
Created January 24, 2012 17:37
First test with Mockito - Point Of Sale - Hola TDD
@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");
}
@isidromerayo
isidromerayo / about.md
Created August 17, 2011 12:17 — forked from kinisoftware/about.md
Programming Achievements: How to Level Up as a Developer