Clean up test names and remove laravel/browser-kit-testing

This commit is contained in:
James Brooks
2018-06-16 21:21:38 +01:00
parent 1593b7b451
commit aa2a39da6d
13 changed files with 444 additions and 405 deletions

View File

@@ -11,6 +11,8 @@
namespace CachetHQ\Tests\Cachet\Api;
use CachetHQ\Cachet\Models\Component;
/**
* This is the component test class.
*
@@ -19,43 +21,46 @@ namespace CachetHQ\Tests\Cachet\Api;
*/
class ComponentTest extends AbstractApiTestCase
{
public function testGetComponents()
public function test_can_get_all_components()
{
$components = factory('CachetHQ\Cachet\Models\Component', 3)->create();
$components = factory(Component::class, 3)->create();
$this->get('/api/v1/components');
$this->seeJsonContains(['id' => $components[0]->id]);
$this->seeJsonContains(['id' => $components[1]->id]);
$this->seeJsonContains(['id' => $components[2]->id]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components');
$response->assertStatus(200);
$response->assertJsonFragment(['id' => $components[0]->id]);
$response->assertJsonFragment(['id' => $components[1]->id]);
$response->assertJsonFragment(['id' => $components[2]->id]);
}
public function testGetInvalidComponent()
public function test_cannot_get_invalid_component()
{
$this->get('/api/v1/components/1');
$this->assertResponseStatus(404);
$response = $this->json('GET', '/api/v1/components/1');
$response->assertStatus(404);
}
public function testPostComponentUnauthorized()
public function test_cannot_create_component_without_authorization()
{
$this->post('/api/v1/components');
$response = $this->json('POST', '/api/v1/components');
$this->assertResponseStatus(401);
$response->assertStatus(401);
}
public function testPostComponentNoData()
public function test_cannot_create_component_without_data()
{
$this->beUser();
$this->post('/api/v1/components');
$this->assertResponseStatus(400);
$response = $this->json('POST', '/api/v1/components');
$response->assertStatus(400);
}
public function testPostComponent()
public function test_can_create_component()
{
$this->beUser();
$this->post('/api/v1/components', [
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -64,15 +69,16 @@ class ComponentTest extends AbstractApiTestCase
'group_id' => 1,
'enabled' => true,
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testPostComponentWithoutEnabledField()
public function test_can_create_component_without_enabled_field()
{
$this->beUser();
$this->post('/api/v1/components', [
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -80,15 +86,16 @@ class ComponentTest extends AbstractApiTestCase
'order' => 1,
'group_id' => 1,
]);
$this->seeJsonContains(['name' => 'Foo', 'enabled' => true]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'enabled' => true]);
}
public function testPostComponentWithMetaData()
public function test_can_create_component_with_meta_data()
{
$this->beUser();
$this->post('/api/v1/components', [
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -101,19 +108,21 @@ class ComponentTest extends AbstractApiTestCase
],
]);
$this->seeJsonContains([
'meta' => [
$response->assertStatus(200);
$response->assertJsonFragment([
'name' => 'Foo',
'status' => 1,
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
],
]);
$this->assertResponseOk();
}
public function testPostDisabledComponent()
public function test_can_create_disabled_component()
{
$this->beUser();
$this->post('/api/v1/components', [
$response = $this->json('POST', '/api/v1/components', [
'name' => 'Foo',
'description' => 'Bar',
'status' => 1,
@@ -122,62 +131,65 @@ class ComponentTest extends AbstractApiTestCase
'group_id' => 1,
'enabled' => 0,
]);
$this->seeJsonContains(['name' => 'Foo', 'enabled' => false]);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo', 'enabled' => false]);
}
public function testGetNewComponent()
public function test_can_get_newly_created_component()
{
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->get('/api/v1/components/1');
$this->seeJsonContains(['name' => $component->name]);
$this->assertResponseOk();
$response = $this->json('GET', '/api/v1/components/1');
$response->assertStatus(200);
$response->assertJsonFragment(['name' => $component->name]);
}
public function testPutComponent()
public function test_can_update_component()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->put('/api/v1/components/1', [
$response = $this->json('PUT', '/api/v1/components/1', [
'name' => 'Foo',
]);
$this->seeJsonContains(['name' => 'Foo']);
$this->assertResponseOk();
$response->assertStatus(200);
$response->assertJsonFragment(['name' => 'Foo']);
}
public function testPutComponentWithMetaData()
public function test_can_update_component_with_meta_data()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create([
$component = factory(Component::class)->create([
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
],
]);
$this->put('/api/v1/components/1', [
$response = $this->json('PUT', '/api/v1/components/1', [
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
'foo' => 'bar',
],
]);
$this->seeJsonContains([
$response->assertStatus(200);
$response->assertJsonFragment([
'meta' => [
'uuid' => '172ff3fb-41f7-49d3-8bcd-f57b53627fa0',
'foo' => 'bar',
],
]);
$this->assertResponseOk();
}
public function testDeleteComponent()
public function test_can_delete_component()
{
$this->beUser();
$component = factory('CachetHQ\Cachet\Models\Component')->create();
$component = factory(Component::class)->create();
$this->delete('/api/v1/components/1');
$this->assertResponseStatus(204);
$response = $this->delete('/api/v1/components/1');
$response->assertStatus(204);
}
}