Skip to content

Commit 036e608

Browse files
authored
Merge pull request #18 from JoeBocock/develop
Pull in develop
2 parents d1db58b + 25af405 commit 036e608

File tree

10 files changed

+149
-83
lines changed

10 files changed

+149
-83
lines changed

.env.example

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ LOG_CHANNEL=stack
88
LOG_LEVEL=debug
99

1010
DB_CONNECTION=mysql
11-
DB_HOST=127.0.0.1
11+
DB_HOST=mariadb
1212
DB_PORT=3306
1313
DB_DATABASE=knockt
14-
DB_USERNAME=root
15-
DB_PASSWORD=
14+
DB_USERNAME=sail
15+
DB_PASSWORD=password
1616

1717
BROADCAST_DRIVER=log
1818
CACHE_DRIVER=file

database/factories/RowFactory.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Database\Factories;
44

5+
use App\Models\Machine;
56
use App\Models\Row;
67
use Illuminate\Database\Eloquent\Factories\Factory;
78

@@ -23,7 +24,7 @@ public function definition()
2324
{
2425
return [
2526
'name' => $this->faker->word(),
26-
'machine_id' => rand(1, 10),
27+
'machine_id' => Machine::factory(),
2728
];
2829
}
29-
}
30+
}

database/factories/SlotFactory.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Database\Factories;
44

5+
use App\Models\Product;
6+
use App\Models\Row;
57
use App\Models\Slot;
68
use Illuminate\Database\Eloquent\Factories\Factory;
79

@@ -23,8 +25,8 @@ public function definition()
2325
{
2426
return [
2527
'name' => $this->faker->bothify('#?'),
26-
'row_id' => rand(1, 30),
27-
'product_id' => rand(1, 100),
28+
'row_id' => Row::factory(),
29+
'product_id' => Product::factory(),
2830
];
2931
}
30-
}
32+
}

docker-compose.yml

Lines changed: 4 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: '3'
33
services:
44
laravel.test:
55
build:
6-
context: ./vendor/laravel/sail/runtimes/8.0
6+
context: ./vendor/laravel/sail/runtimes/7.4
77
dockerfile: Dockerfile
88
args:
99
WWWGROUP: '${WWWGROUP}'
@@ -18,11 +18,10 @@ services:
1818
networks:
1919
- sail
2020
depends_on:
21-
- mysql
21+
- mariadb
2222
- redis
23-
- selenium
24-
mysql:
25-
image: 'mysql:8.0'
23+
mariadb:
24+
image: 'mariadb'
2625
ports:
2726
- '${FORWARD_DB_PORT:-3306}:3306'
2827
environment:
@@ -47,27 +46,6 @@ services:
4746
- sail
4847
healthcheck:
4948
test: ["CMD", "redis-cli", "ping"]
50-
meilisearch:
51-
image: 'getmeili/meilisearch:latest'
52-
ports:
53-
- '${FORWARD_MEILISEARCH_PORT:-7700}:7700'
54-
volumes:
55-
- 'sailmeilisearch:/data.ms'
56-
networks:
57-
- sail
58-
mailhog:
59-
image: 'mailhog/mailhog:latest'
60-
ports:
61-
- '${FORWARD_MAILHOG_PORT:-1025}:1025'
62-
- '${FORWARD_MAILHOG_DASHBOARD_PORT:-8025}:8025'
63-
networks:
64-
- sail
65-
selenium:
66-
image: 'selenium/standalone-chrome'
67-
volumes:
68-
- '/dev/shm:/dev/shm'
69-
networks:
70-
- sail
7149
networks:
7250
sail:
7351
driver: bridge
@@ -76,5 +54,3 @@ volumes:
7654
driver: local
7755
sailredis:
7856
driver: local
79-
sailmeilisearch:
80-
driver: local

tests/Feature/ExampleTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
namespace Tests\Unit;
4+
5+
use Tests\TestCase;
6+
7+
class ExampleTest extends TestCase
8+
{
9+
/**
10+
* Assert True.
11+
*
12+
* @test
13+
*
14+
* @return void
15+
*/
16+
public function it_tests(): void
17+
{
18+
$this->assertTrue(true);
19+
}
20+
}

tests/TestCase.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,4 @@ abstract class TestCase extends BaseTestCase
99
{
1010
use CreatesApplication;
1111
use RefreshDatabase;
12-
13-
protected $seed = true;
1412
}

tests/Unit/MachineTest.php

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ class MachineTest extends TestCase
1414
*
1515
* @return void
1616
*/
17-
public function theyCanBeRetrieved(): void
17+
public function they_can_be_retrieved(): void
1818
{
19+
Machine::factory()->create();
20+
1921
$response = $this->get('/api/machines');
2022

2123
$response->assertStatus(200);
24+
$this->assertNotEmpty($response['data']);
2225
}
2326

2427
/**
@@ -28,11 +31,12 @@ public function theyCanBeRetrieved(): void
2831
*
2932
* @return void
3033
*/
31-
public function itCanBeStored(): void
34+
public function it_can_be_stored(): void
3235
{
3336
$response = $this->post('/api/machines', Machine::factory()->raw());
3437

3538
$response->assertStatus(201);
39+
$this->assertNotEmpty($response['data']);
3640
}
3741

3842
/**
@@ -42,11 +46,14 @@ public function itCanBeStored(): void
4246
*
4347
* @return void
4448
*/
45-
public function itCanBeRetrieved(): void
49+
public function it_can_be_retrieved(): void
4650
{
47-
$response = $this->get('/api/machines/'.Machine::first()->id);
51+
$machine = Machine::factory()->create();
52+
53+
$response = $this->get("/api/machines/{$machine->id}");
4854

4955
$response->assertStatus(200);
56+
$this->assertEquals($machine->name, $response['data']['name']);
5057
}
5158

5259
/**
@@ -56,11 +63,15 @@ public function itCanBeRetrieved(): void
5663
*
5764
* @return void
5865
*/
59-
public function itCanBeUpdated(): void
66+
public function it_can_be_updated(): void
6067
{
61-
$response = $this->put('/api/machines/'.Machine::first()->id, Machine::factory()->raw());
68+
$machine = Machine::factory()->create();
69+
70+
$response = $this->put("/api/machines/{$machine->id}", Machine::factory()->raw());
6271

6372
$response->assertStatus(200);
73+
$this->assertEquals($machine->id, $response['data']['id']);
74+
$this->assertNotEquals($machine->name, $response['data']['name']);
6475
}
6576

6677
/**
@@ -70,10 +81,13 @@ public function itCanBeUpdated(): void
7081
*
7182
* @return void
7283
*/
73-
public function itCanBeDestroyed(): void
84+
public function it_can_be_destroyed(): void
7485
{
75-
$response = $this->delete('/api/machines/'.Machine::first()->id);
86+
$machine = Machine::factory()->create();
87+
88+
$response = $this->delete("/api/machines/{$machine->id}");
7689

7790
$response->assertStatus(204);
91+
$this->assertDatabaseMissing('machines', ['id' => $machine->id]);
7892
}
79-
}
93+
}

tests/Unit/ProductTest.php

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ class ProductTest extends TestCase
1414
*
1515
* @return void
1616
*/
17-
public function theyCanBeRetrieved(): void
17+
public function they_can_be_retrieved(): void
1818
{
19-
$response = $this->call('GET', '/api/products');
19+
Product::factory()->create();
20+
21+
$response = $this->get('/api/products');
2022

2123
$response->assertStatus(200);
24+
$this->assertNotEmpty($response['data']);
2225
}
2326

2427
/**
@@ -28,11 +31,12 @@ public function theyCanBeRetrieved(): void
2831
*
2932
* @return void
3033
*/
31-
public function itCanBeStored(): void
34+
public function it_can_be_stored(): void
3235
{
3336
$response = $this->post('/api/products', Product::factory()->raw());
3437

3538
$response->assertStatus(201);
39+
$this->assertNotEmpty($response['data']);
3640
}
3741

3842
/**
@@ -42,11 +46,14 @@ public function itCanBeStored(): void
4246
*
4347
* @return void
4448
*/
45-
public function itCanBeRetrieved(): void
49+
public function it_can_be_retrieved(): void
4650
{
47-
$response = $this->call('GET', '/api/products/'.Product::first()->id);
51+
$product = Product::factory()->create();
52+
53+
$response = $this->get("/api/products/{$product->id}");
4854

4955
$response->assertStatus(200);
56+
$this->assertEquals($product->name, $response['data']['name']);
5057
}
5158

5259
/**
@@ -56,11 +63,15 @@ public function itCanBeRetrieved(): void
5663
*
5764
* @return void
5865
*/
59-
public function itCanBeUpdated(): void
66+
public function it_can_be_updated(): void
6067
{
61-
$response = $this->put('/api/products/'.Product::first()->id, Product::factory()->raw());
68+
$product = Product::factory()->create();
69+
70+
$response = $this->put("/api/products/{$product->id}", Product::factory()->raw());
6271

6372
$response->assertStatus(200);
73+
$this->assertEquals($product->id, $response['data']['id']);
74+
$this->assertNotEquals($product->name, $response['data']['name']);
6475
}
6576

6677
/**
@@ -70,10 +81,13 @@ public function itCanBeUpdated(): void
7081
*
7182
* @return void
7283
*/
73-
public function itCanBeDestroyed(): void
84+
public function it_can_be_destroyed(): void
7485
{
75-
$response = $this->delete('/api/products/'.Product::first()->id);
86+
$product = Product::factory()->create();
87+
88+
$response = $this->delete("/api/products/{$product->id}");
7689

7790
$response->assertStatus(204);
91+
$this->assertDatabaseMissing('products', ['id' => $product->id]);
7892
}
79-
}
93+
}

tests/Unit/RowTest.php

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@ class RowTest extends TestCase
1515
*
1616
* @return void
1717
*/
18-
public function theyCanBeRetrieved(): void
18+
public function they_can_be_retrieved(): void
1919
{
20-
$response = $this->call('GET', '/api/rows', ['machine_id' => Machine::first()->id]);
20+
$row = Row::factory()->create();
21+
22+
$response = $this->call('GET', '/api/rows', ['machine_id' => $row->machine_id]);
2123

2224
$response->assertStatus(200);
25+
$this->assertNotEmpty($response['data']);
2326
}
2427

2528
/**
@@ -29,14 +32,17 @@ public function theyCanBeRetrieved(): void
2932
*
3033
* @return void
3134
*/
32-
public function itCanBeStored(): void
35+
public function it_can_be_stored(): void
3336
{
37+
$machine = Machine::factory()->create();
38+
3439
$response = $this->post('/api/rows', array_merge(
3540
Row::factory()->raw(),
36-
['machine_id' => Row::first()->machine_id]
41+
['machine_id' => $machine->id]
3742
));
3843

3944
$response->assertStatus(201);
45+
$this->assertNotEmpty($response['data']);
4046
}
4147

4248
/**
@@ -46,11 +52,14 @@ public function itCanBeStored(): void
4652
*
4753
* @return void
4854
*/
49-
public function itCanBeRetrieved(): void
55+
public function it_can_be_retrieved(): void
5056
{
51-
$response = $this->call('GET', '/api/rows/'.Row::first()->id);
57+
$row = Row::factory()->create();
58+
59+
$response = $this->call('GET', "/api/rows/{$row->id}");
5260

5361
$response->assertStatus(200);
62+
$this->assertEquals($row->name, $response['data']['name']);
5463
}
5564

5665
/**
@@ -60,11 +69,15 @@ public function itCanBeRetrieved(): void
6069
*
6170
* @return void
6271
*/
63-
public function itCanBeUpdated(): void
72+
public function it_can_be_updated(): void
6473
{
65-
$response = $this->put('/api/rows/'.Row::first()->id, Row::factory()->raw());
74+
$row = Row::factory()->create();
75+
76+
$response = $this->put("/api/rows/{$row->id}", Row::factory()->raw());
6677

6778
$response->assertStatus(200);
79+
$this->assertEquals($row->id, $response['data']['id']);
80+
$this->assertNotEquals($row->name, $response['data']['name']);
6881
}
6982

7083
/**
@@ -74,10 +87,13 @@ public function itCanBeUpdated(): void
7487
*
7588
* @return void
7689
*/
77-
public function itCanBeDestroyed(): void
90+
public function it_can_be_destroyed(): void
7891
{
79-
$response = $this->delete('/api/rows/'.Row::first()->id);
92+
$row = Row::factory()->create();
93+
94+
$response = $this->delete("/api/rows/{$row->id}");
8095

8196
$response->assertStatus(204);
97+
$this->assertDatabaseMissing('rows', ['id' => $row->id]);
8298
}
83-
}
99+
}

0 commit comments

Comments
 (0)