|
8 | 8 | use WPGraphQL\Logging\Admin\View\Download\DownloadLogService; |
9 | 9 | use WPGraphQL\Logging\Logger\Database\LogsRepository; |
10 | 10 | use WPGraphQL\Logging\Logger\Database\DatabaseEntity; |
11 | | - |
| 11 | +use Mockery; |
12 | 12 |
|
13 | 13 |
|
14 | 14 | /** |
@@ -59,11 +59,6 @@ public function setUp(): void { |
59 | 59 | $this->repository = new LogsRepository(); |
60 | 60 | } |
61 | 61 |
|
62 | | - public function tearDown(): void { |
63 | | - $this->repository->delete_all(); |
64 | | - parent::tearDown(); |
65 | | - } |
66 | | - |
67 | 62 | public function set_as_admin(): void { |
68 | 63 | $admin_user = $this->factory->user->create(['role' => 'administrator']); |
69 | 64 | wp_set_current_user($admin_user); |
@@ -100,8 +95,26 @@ public function test_generate_csv_requires_valid_log_id_in_database(): void { |
100 | 95 |
|
101 | 96 | public function test_generate_csv_returns_valid_csv(): void { |
102 | 97 | $this->set_as_admin(); |
103 | | - $entity = DatabaseEntity::create(...array_values($this->fixture)); |
104 | | - $log_id = $entity->save(); |
| 98 | + // Mock a database entity instead of creating a real one |
| 99 | + $entity = \Mockery::mock(DatabaseEntity::class); |
| 100 | + $entity->shouldReceive('get_id')->andReturn(123); |
| 101 | + $entity->shouldReceive('get_datetime')->andReturn('2023-01-01 12:00:00'); |
| 102 | + $entity->shouldReceive('get_level')->andReturn($this->fixture['level']); |
| 103 | + $entity->shouldReceive('get_level_name')->andReturn($this->fixture['level_name']); |
| 104 | + $entity->shouldReceive('get_message')->andReturn($this->fixture['message']); |
| 105 | + $entity->shouldReceive('get_channel')->andReturn($this->fixture['channel']); |
| 106 | + $entity->shouldReceive('get_query')->andReturn($this->fixture['extra']['wpgraphql_query']); |
| 107 | + $entity->shouldReceive('get_context')->andReturn($this->fixture['context']); |
| 108 | + $entity->shouldReceive('get_extra')->andReturn($this->fixture['extra']); |
| 109 | + |
| 110 | + // Mock the repository to return our mocked entity |
| 111 | + $this->repository = \Mockery::mock(LogsRepository::class); |
| 112 | + $this->repository->shouldReceive('find_by_id')->with(123)->andReturn($entity); |
| 113 | + |
| 114 | + // Inject the mocked repository into the service |
| 115 | + $this->service = new DownloadLogService($this->repository); |
| 116 | + |
| 117 | + $log_id = 123; |
105 | 118 |
|
106 | 119 |
|
107 | 120 | $headers = $this->service->get_headers($entity); |
|
0 commit comments