Slide 1

Slide 1 text

Mock Mock Mock Mock Mock Mock Mocking-Frameworks Mocking-Frameworks Claudio Zizza @SenseException

Slide 2

Slide 2 text

Test your code! (Duh!)

Slide 3

Slide 3 text

Tests & Dependencies

Slide 4

Slide 4 text

Dependencies I only want to test/run this small part :-(

Slide 5

Slide 5 text

Test Doubles Mostly used in tests: ● Dummies ● Stubs ● Mocks (We do only Mocks for now)

Slide 6

Slide 6 text

PHPUnit $mockFw = new PHPUnit_Framework_MockObject_Generator(); $math = $mockFw->getMock(MathInterface::class); $math->expects(new PHPUnit_Framework_MockObject_Matcher_InvokedAtLeastOnce()) ->method('sum') ->with(1, 1) ->willReturn(2);

Slide 7

Slide 7 text

Prophecy $mockFw = new Prophet(); $prophecy = $mockFw->prophesize(MathInterface::class); $prophecy->sum(1, 1) ->willReturn(2) ->shouldBeCalledTimes(1); $math = $prophecy->reveal();

Slide 8

Slide 8 text

Mockery $math = Mockery::mock(MathInterface::class); $math->shouldReceive('sum') ->once() ->with(1, 1) ->andReturn(2);

Slide 9

Slide 9 text

vfsStream baseDir = vfsStream::setup('dir'); mkdir(vfsStream::url('dir') . '/' . 'myDir'); Mooooock?

Slide 10

Slide 10 text

bovigo/callmap math = NewInstance::of(MathInterface::class) ->mapCalls(['sum' => 2]); // ... verify($math, 'sum')->wasCalledOnce();

Slide 11

Slide 11 text

Phake $math = Phake::mock(MathInterface::class); Phake::when($math)->sum(1, 1)->thenReturn(2); // ... Phake::verify($math, Phake::times(1))->sum(1, 1);

Slide 12

Slide 12 text

Examples Let's mock mock mock: https://github.com/SenseException/mock-mock-mock

Slide 13

Slide 13 text

Thank you Thank you Claudio Zizza @SenseException