|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Rezzza\MocoBehatExtension\Tests\Units; |
| 4 | + |
| 5 | +use mageekguy\atoum; |
| 6 | + |
| 7 | +class MocoWriter extends atoum |
| 8 | +{ |
| 9 | + public function test_it_should_write_request_and_response() |
| 10 | + { |
| 11 | + $this |
| 12 | + ->given( |
| 13 | + $this->newTestedInstance('fixtures.json', '127.0.0.1', '8888'), |
| 14 | + $this->function->file_put_contents = true, |
| 15 | + $this->function->stream_socket_client = true, |
| 16 | + $this->testedInstance->mockHttpCall(['uri' => '/coucou'], ['status' => '404']) |
| 17 | + ) |
| 18 | + ->when( |
| 19 | + $this->testedInstance->writeForMoco() |
| 20 | + ) |
| 21 | + ->then |
| 22 | + ->function('file_put_contents') |
| 23 | + ->wasCalledWithArguments('fixtures.json', json_encode([['request' => ['uri' => '/coucou'], 'response' => ['status' => '404']]])) |
| 24 | + ->once() |
| 25 | + ; |
| 26 | + } |
| 27 | + |
| 28 | + public function test_it_should_reset_payload_to_moco() |
| 29 | + { |
| 30 | + $this |
| 31 | + ->given( |
| 32 | + $this->newTestedInstance('fixtures.json', '127.0.0.1', '8888'), |
| 33 | + $this->function->file_put_contents = true, |
| 34 | + $this->function->stream_socket_client = true, |
| 35 | + $this->testedInstance->mockHttpCall(['uri' => '/coucou'], ['status' => '404']) |
| 36 | + ) |
| 37 | + ->when( |
| 38 | + $this->testedInstance->reset() |
| 39 | + ) |
| 40 | + ->then |
| 41 | + ->function('file_put_contents') |
| 42 | + ->wasCalledWithArguments('fixtures.json', json_encode([])) |
| 43 | + ->once() |
| 44 | + ; |
| 45 | + } |
| 46 | + |
| 47 | + public function test_it_should_write_events_if_present() |
| 48 | + { |
| 49 | + $this |
| 50 | + ->given( |
| 51 | + $this->newTestedInstance('fixtures.json', '127.0.0.1', '8888'), |
| 52 | + $this->function->file_put_contents = true, |
| 53 | + $this->function->stream_socket_client = true, |
| 54 | + $this->testedInstance->mockHttpCall(['uri' => '/coucou'], ['status' => '404'], ['complete' => 'ok']) |
| 55 | + ) |
| 56 | + ->when( |
| 57 | + $this->testedInstance->writeForMoco() |
| 58 | + ) |
| 59 | + ->then |
| 60 | + ->function('file_put_contents') |
| 61 | + ->wasCalledWithArguments('fixtures.json', json_encode([ |
| 62 | + ['request' => ['uri' => '/coucou'], 'response' => ['status' => '404'], 'on' => ['complete' => 'ok']] |
| 63 | + ])) |
| 64 | + ->once() |
| 65 | + ; |
| 66 | + } |
| 67 | +} |
0 commit comments