diff --git a/tests/Unit/Services/Eggs/EggConfigurationServiceTest.php b/tests/Unit/Services/Eggs/EggConfigurationServiceTest.php new file mode 100644 index 000000000..1dd124ab4 --- /dev/null +++ b/tests/Unit/Services/Eggs/EggConfigurationServiceTest.php @@ -0,0 +1,90 @@ +repository = m::mock(EggRepositoryInterface::class); + + $this->service = new EggConfigurationService($this->repository); + } + + /** + * Test that the correct array is returned. + */ + public function testCorrectArrayIsReturned() + { + $egg = factory(Egg::class)->make([ + 'config_startup' => '{"test": "start"}', + 'config_stop' => 'test', + 'config_files' => '{"test": "file"}', + 'config_logs' => '{"test": "logs"}', + ]); + + $response = $this->service->handle($egg); + $this->assertNotEmpty($response); + $this->assertTrue(is_array($response), 'Assert response is an array.'); + $this->assertArrayHasKey('startup', $response); + $this->assertArrayHasKey('stop', $response); + $this->assertArrayHasKey('configs', $response); + $this->assertArrayHasKey('log', $response); + $this->assertArrayHasKey('query', $response); + $this->assertEquals('start', object_get($response['startup'], 'test')); + $this->assertEquals('test', 'test'); + $this->assertEquals('file', object_get($response['configs'], 'test')); + $this->assertEquals('logs', object_get($response['log'], 'test')); + $this->assertEquals('none', $response['query']); + } + + /** + * Test that an integer referencing a model can be passed in place of the model. + */ + public function testFunctionHandlesIntegerPassedInPlaceOfModel() + { + $egg = factory(Egg::class)->make([ + 'config_startup' => '{"test": "start"}', + 'config_stop' => 'test', + 'config_files' => '{"test": "file"}', + 'config_logs' => '{"test": "logs"}', + ]); + + $this->repository->shouldReceive('getWithCopyAttributes')->with($egg->id)->once()->andReturn($egg); + + $response = $this->service->handle($egg->id); + $this->assertNotEmpty($response); + $this->assertTrue(is_array($response), 'Assert response is an array.'); + $this->assertArrayHasKey('startup', $response); + $this->assertArrayHasKey('stop', $response); + $this->assertArrayHasKey('configs', $response); + $this->assertArrayHasKey('log', $response); + $this->assertArrayHasKey('query', $response); + $this->assertEquals('start', object_get($response['startup'], 'test')); + $this->assertEquals('test', 'test'); + $this->assertEquals('file', object_get($response['configs'], 'test')); + $this->assertEquals('logs', object_get($response['log'], 'test')); + $this->assertEquals('none', $response['query']); + } +}