Skip to content

Commit

Permalink
Merge pull request #18 from JoeBocock/develop
Browse files Browse the repository at this point in the history
Pull in develop
  • Loading branch information
JoeBocock authored Apr 25, 2021
2 parents d1db58b + 25af405 commit 036e608
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 83 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ LOG_CHANNEL=stack
LOG_LEVEL=debug

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_HOST=mariadb
DB_PORT=3306
DB_DATABASE=knockt
DB_USERNAME=root
DB_PASSWORD=
DB_USERNAME=sail
DB_PASSWORD=password

BROADCAST_DRIVER=log
CACHE_DRIVER=file
Expand Down
5 changes: 3 additions & 2 deletions database/factories/RowFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Database\Factories;

use App\Models\Machine;
use App\Models\Row;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand All @@ -23,7 +24,7 @@ public function definition()
{
return [
'name' => $this->faker->word(),
'machine_id' => rand(1, 10),
'machine_id' => Machine::factory(),
];
}
}
}
8 changes: 5 additions & 3 deletions database/factories/SlotFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Database\Factories;

use App\Models\Product;
use App\Models\Row;
use App\Models\Slot;
use Illuminate\Database\Eloquent\Factories\Factory;

Expand All @@ -23,8 +25,8 @@ public function definition()
{
return [
'name' => $this->faker->bothify('#?'),
'row_id' => rand(1, 30),
'product_id' => rand(1, 100),
'row_id' => Row::factory(),
'product_id' => Product::factory(),
];
}
}
}
32 changes: 4 additions & 28 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ version: '3'
services:
laravel.test:
build:
context: ./vendor/laravel/sail/runtimes/8.0
context: ./vendor/laravel/sail/runtimes/7.4
dockerfile: Dockerfile
args:
WWWGROUP: '${WWWGROUP}'
Expand All @@ -18,11 +18,10 @@ services:
networks:
- sail
depends_on:
- mysql
- mariadb
- redis
- selenium
mysql:
image: 'mysql:8.0'
mariadb:
image: 'mariadb'
ports:
- '${FORWARD_DB_PORT:-3306}:3306'
environment:
Expand All @@ -47,27 +46,6 @@ services:
- sail
healthcheck:
test: ["CMD", "redis-cli", "ping"]
meilisearch:
image: 'getmeili/meilisearch:latest'
ports:
- '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
volumes:
- 'sailmeilisearch:/data.ms'
networks:
- sail
mailhog:
image: 'mailhog/mailhog:latest'
ports:
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
networks:
- sail
selenium:
image: 'selenium/standalone-chrome'
volumes:
- '/dev/shm:/dev/shm'
networks:
- sail
networks:
sail:
driver: bridge
Expand All @@ -76,5 +54,3 @@ volumes:
driver: local
sailredis:
driver: local
sailmeilisearch:
driver: local
20 changes: 20 additions & 0 deletions tests/Feature/ExampleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Unit;

use Tests\TestCase;

class ExampleTest extends TestCase
{
/**
* Assert True.
*
* @test
*
* @return void
*/
public function it_tests(): void
{
$this->assertTrue(true);
}
}
2 changes: 0 additions & 2 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,4 @@ abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use RefreshDatabase;

protected $seed = true;
}
32 changes: 23 additions & 9 deletions tests/Unit/MachineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class MachineTest extends TestCase
*
* @return void
*/
public function theyCanBeRetrieved(): void
public function they_can_be_retrieved(): void
{
Machine::factory()->create();

$response = $this->get('/api/machines');

$response->assertStatus(200);
$this->assertNotEmpty($response['data']);
}

/**
Expand All @@ -28,11 +31,12 @@ public function theyCanBeRetrieved(): void
*
* @return void
*/
public function itCanBeStored(): void
public function it_can_be_stored(): void
{
$response = $this->post('/api/machines', Machine::factory()->raw());

$response->assertStatus(201);
$this->assertNotEmpty($response['data']);
}

/**
Expand All @@ -42,11 +46,14 @@ public function itCanBeStored(): void
*
* @return void
*/
public function itCanBeRetrieved(): void
public function it_can_be_retrieved(): void
{
$response = $this->get('/api/machines/'.Machine::first()->id);
$machine = Machine::factory()->create();

$response = $this->get("/api/machines/{$machine->id}");

$response->assertStatus(200);
$this->assertEquals($machine->name, $response['data']['name']);
}

/**
Expand All @@ -56,11 +63,15 @@ public function itCanBeRetrieved(): void
*
* @return void
*/
public function itCanBeUpdated(): void
public function it_can_be_updated(): void
{
$response = $this->put('/api/machines/'.Machine::first()->id, Machine::factory()->raw());
$machine = Machine::factory()->create();

$response = $this->put("/api/machines/{$machine->id}", Machine::factory()->raw());

$response->assertStatus(200);
$this->assertEquals($machine->id, $response['data']['id']);
$this->assertNotEquals($machine->name, $response['data']['name']);
}

/**
Expand All @@ -70,10 +81,13 @@ public function itCanBeUpdated(): void
*
* @return void
*/
public function itCanBeDestroyed(): void
public function it_can_be_destroyed(): void
{
$response = $this->delete('/api/machines/'.Machine::first()->id);
$machine = Machine::factory()->create();

$response = $this->delete("/api/machines/{$machine->id}");

$response->assertStatus(204);
$this->assertDatabaseMissing('machines', ['id' => $machine->id]);
}
}
}
34 changes: 24 additions & 10 deletions tests/Unit/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ class ProductTest extends TestCase
*
* @return void
*/
public function theyCanBeRetrieved(): void
public function they_can_be_retrieved(): void
{
$response = $this->call('GET', '/api/products');
Product::factory()->create();

$response = $this->get('/api/products');

$response->assertStatus(200);
$this->assertNotEmpty($response['data']);
}

/**
Expand All @@ -28,11 +31,12 @@ public function theyCanBeRetrieved(): void
*
* @return void
*/
public function itCanBeStored(): void
public function it_can_be_stored(): void
{
$response = $this->post('/api/products', Product::factory()->raw());

$response->assertStatus(201);
$this->assertNotEmpty($response['data']);
}

/**
Expand All @@ -42,11 +46,14 @@ public function itCanBeStored(): void
*
* @return void
*/
public function itCanBeRetrieved(): void
public function it_can_be_retrieved(): void
{
$response = $this->call('GET', '/api/products/'.Product::first()->id);
$product = Product::factory()->create();

$response = $this->get("/api/products/{$product->id}");

$response->assertStatus(200);
$this->assertEquals($product->name, $response['data']['name']);
}

/**
Expand All @@ -56,11 +63,15 @@ public function itCanBeRetrieved(): void
*
* @return void
*/
public function itCanBeUpdated(): void
public function it_can_be_updated(): void
{
$response = $this->put('/api/products/'.Product::first()->id, Product::factory()->raw());
$product = Product::factory()->create();

$response = $this->put("/api/products/{$product->id}", Product::factory()->raw());

$response->assertStatus(200);
$this->assertEquals($product->id, $response['data']['id']);
$this->assertNotEquals($product->name, $response['data']['name']);
}

/**
Expand All @@ -70,10 +81,13 @@ public function itCanBeUpdated(): void
*
* @return void
*/
public function itCanBeDestroyed(): void
public function it_can_be_destroyed(): void
{
$response = $this->delete('/api/products/'.Product::first()->id);
$product = Product::factory()->create();

$response = $this->delete("/api/products/{$product->id}");

$response->assertStatus(204);
$this->assertDatabaseMissing('products', ['id' => $product->id]);
}
}
}
38 changes: 27 additions & 11 deletions tests/Unit/RowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ class RowTest extends TestCase
*
* @return void
*/
public function theyCanBeRetrieved(): void
public function they_can_be_retrieved(): void
{
$response = $this->call('GET', '/api/rows', ['machine_id' => Machine::first()->id]);
$row = Row::factory()->create();

$response = $this->call('GET', '/api/rows', ['machine_id' => $row->machine_id]);

$response->assertStatus(200);
$this->assertNotEmpty($response['data']);
}

/**
Expand All @@ -29,14 +32,17 @@ public function theyCanBeRetrieved(): void
*
* @return void
*/
public function itCanBeStored(): void
public function it_can_be_stored(): void
{
$machine = Machine::factory()->create();

$response = $this->post('/api/rows', array_merge(
Row::factory()->raw(),
['machine_id' => Row::first()->machine_id]
['machine_id' => $machine->id]
));

$response->assertStatus(201);
$this->assertNotEmpty($response['data']);
}

/**
Expand All @@ -46,11 +52,14 @@ public function itCanBeStored(): void
*
* @return void
*/
public function itCanBeRetrieved(): void
public function it_can_be_retrieved(): void
{
$response = $this->call('GET', '/api/rows/'.Row::first()->id);
$row = Row::factory()->create();

$response = $this->call('GET', "/api/rows/{$row->id}");

$response->assertStatus(200);
$this->assertEquals($row->name, $response['data']['name']);
}

/**
Expand All @@ -60,11 +69,15 @@ public function itCanBeRetrieved(): void
*
* @return void
*/
public function itCanBeUpdated(): void
public function it_can_be_updated(): void
{
$response = $this->put('/api/rows/'.Row::first()->id, Row::factory()->raw());
$row = Row::factory()->create();

$response = $this->put("/api/rows/{$row->id}", Row::factory()->raw());

$response->assertStatus(200);
$this->assertEquals($row->id, $response['data']['id']);
$this->assertNotEquals($row->name, $response['data']['name']);
}

/**
Expand All @@ -74,10 +87,13 @@ public function itCanBeUpdated(): void
*
* @return void
*/
public function itCanBeDestroyed(): void
public function it_can_be_destroyed(): void
{
$response = $this->delete('/api/rows/'.Row::first()->id);
$row = Row::factory()->create();

$response = $this->delete("/api/rows/{$row->id}");

$response->assertStatus(204);
$this->assertDatabaseMissing('rows', ['id' => $row->id]);
}
}
}
Loading

0 comments on commit 036e608

Please sign in to comment.