-
Notifications
You must be signed in to change notification settings - Fork 566
Expand file tree
/
Copy pathRequestTableTest.php
More file actions
107 lines (94 loc) · 3.18 KB
/
RequestTableTest.php
File metadata and controls
107 lines (94 loc) · 3.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
declare(strict_types=1);
/**
* CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
* @link https://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license https://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace DebugKit\Test\TestCase\Model\Table;
use Cake\Core\Configure;
use Cake\Database\Driver\Sqlite;
use Cake\Datasource\ConnectionManager;
use Cake\TestSuite\TestCase;
/**
* Tests for request table.
*/
class RequestTableTest extends TestCase
{
/**
* Setup
*
* Skip tests on SQLite as SQLite complains when tables are changed while a connection is open.
*
* @return void
*/
public function setUp(): void
{
parent::setUp();
$connection = ConnectionManager::get('test');
$this->skipIf($connection->getDriver() instanceof Sqlite, 'Schema insertion/removal breaks SQLite');
}
/**
* test that schema is created on-demand.
*
* @return void
*/
public function testInitializeCreatesSchema()
{
$connection = ConnectionManager::get('test');
$stmt = $connection->execute('DROP TABLE IF EXISTS panels');
$stmt->closeCursor();
$stmt = $connection->execute('DROP TABLE IF EXISTS requests');
$stmt->closeCursor();
$this->fetchTable('DebugKit.Requests');
$this->fetchTable('DebugKit.Panels');
$schema = $connection->getSchemaCollection();
$this->assertContains('requests', $schema->listTables());
$this->assertContains('panels', $schema->listTables());
}
/**
* Test the recent finder.
*
* @return void
*/
public function testFindRecent()
{
$table = $this->fetchTable('DebugKit.Requests');
$query = $table->find('recent');
$this->assertSame(10, $query->clause('limit'));
$this->assertNotEmpty($query->clause('order'));
}
/**
* Test the garbage collect.
*
* @return void
*/
public function testGc()
{
/** @var \PHPUnit\Framework\MockObject\MockObject&\DebugKit\Model\Table\RequestsTable $requestsTableMock */
$requestsTableMock = $this->getMockForModel('DebugKit.Requests', ['shouldGc']);
$requestsTableMock->method('shouldGc')
->willReturn(true);
$data = array_fill(0, 10, [
'url' => '/tasks/add',
'content_type' => 'text/html',
'status_code' => 200,
'requested_at' => '2014-08-21 7:41:12',
]);
$requests = $requestsTableMock->newEntities($data);
$this->assertNotFalse($requestsTableMock->saveMany($requests));
$count = $requestsTableMock->find()->count();
$this->assertGreaterThanOrEqual(10, $count);
Configure::write('DebugKit.requestCount', 5);
$requestsTableMock->gc();
$count = $requestsTableMock->find()->count();
$this->assertSame(5, $count);
}
}