| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
- namespace App\Module\Game\Tests;
- use App\Module\Game\Models\Test;
- use App\Module\Game\Services\TestService;
- use Illuminate\Foundation\Testing\DatabaseTransactions;
- use Tests\TestCase;
- class TestTest extends TestCase
- {
- use DatabaseTransactions;
- protected TestService $service;
- protected function setUp(): void
- {
- parent::setUp();
- $this->service = app(TestService::class);
- }
- /**
- * 测试创建数据
- *
- * @return void
- */
- public function test_create(): void
- {
- $data = [
- 'name' => '测试数据',
- 'code' => 'TEST001',
- 'description' => '测试描述'
- ];
- $test = $this->service->create($data);
- $this->assertInstanceOf(Test::class, $test);
- $this->assertEquals($data['name'], $test->name);
- $this->assertEquals($data['code'], $test->code);
- $this->assertEquals($data['description'], $test->description);
- }
- /**
- * 测试获取数据
- *
- * @return void
- */
- public function test_get(): void
- {
- $test = Test::factory()->create();
- $result = $this->service->get($test->id);
- $this->assertInstanceOf(Test::class, $result);
- $this->assertEquals($test->id, $result->id);
- }
- /**
- * 测试更新数据
- *
- * @return void
- */
- public function test_update(): void
- {
- $test = Test::factory()->create();
- $data = [
- 'name' => '更新数据',
- 'code' => 'TEST002'
- ];
- $result = $this->service->update($test->id, $data);
- $this->assertTrue($result);
- $this->assertEquals($data['name'], $test->fresh()->name);
- $this->assertEquals($data['code'], $test->fresh()->code);
- }
- /**
- * 测试删除数据
- *
- * @return void
- */
- public function test_delete(): void
- {
- $test = Test::factory()->create();
- $result = $this->service->delete($test->id);
- $this->assertTrue($result);
- $this->assertNull(Test::find($test->id));
- }
- }
|