Skip to content

Commit 8de66a9

Browse files
authored
Merge pull request #790 from cakephp/gh-ci
Add Github Actions based CI
2 parents 45c2b58 + 2fb8982 commit 8de66a9

File tree

14 files changed

+230
-50
lines changed

14 files changed

+230
-50
lines changed

.github/workflows/ci.yml

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '*'
10+
11+
jobs:
12+
testsuite-linux:
13+
runs-on: ubuntu-18.04
14+
strategy:
15+
fail-fast: false
16+
matrix:
17+
php-version: ['7.2', '7.4']
18+
db-type: [mysql, pgsql, sqlite]
19+
prefer-lowest: ['']
20+
include:
21+
- php-version: '7.2'
22+
db-type: 'sqlite'
23+
prefer-lowest: 'prefer-lowest'
24+
25+
services:
26+
postgres:
27+
image: postgres
28+
ports:
29+
- 5432:5432
30+
env:
31+
POSTGRES_PASSWORD: postgres
32+
33+
steps:
34+
- uses: actions/checkout@v1
35+
with:
36+
fetch-depth: 1
37+
38+
- name: Setup Service
39+
if: matrix.db-type == 'mysql'
40+
run: |
41+
sudo service mysql start
42+
mysql -h 127.0.0.1 -u root -proot -e 'CREATE DATABASE cakephp;'
43+
44+
- name: Setup PHP
45+
uses: shivammathur/setup-php@v2
46+
with:
47+
php-version: ${{ matrix.php-version }}
48+
extensions: mbstring, intl, pdo_${{ matrix.db-type }}
49+
coverage: pcov
50+
51+
- name: Get composer cache directory
52+
id: composer-cache
53+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
54+
55+
- name: Get date part for cache key
56+
id: key-date
57+
run: echo "::set-output name=date::$(date +'%Y-%m')"
58+
59+
- name: Cache composer dependencies
60+
uses: actions/cache@v1
61+
with:
62+
path: ${{ steps.composer-cache.outputs.dir }}
63+
key: ${{ runner.os }}-composer-${{ steps.key-date.outputs.date }}-${{ hashFiles('composer.json') }}-${{ matrix.prefer-lowest }}
64+
65+
- name: Composer install
66+
run: |
67+
if ${{ matrix.prefer-lowest == 'prefer-lowest' }}; then
68+
composer update --prefer-lowest --prefer-stable
69+
else
70+
composer install
71+
fi
72+
73+
- name: Run PHPUnit
74+
run: |
75+
if [[ ${{ matrix.db-type }} == 'sqlite' ]]; then
76+
export DB_URL='sqlite:///:memory:'
77+
fi
78+
if [[ ${{ matrix.db-type }} == 'mysql' ]]; then
79+
export DB_URL='mysql://root:[email protected]/cakephp'
80+
fi
81+
if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then
82+
export DB_URL='postgres://postgres:[email protected]/postgres'
83+
fi
84+
if [[ ${{ matrix.php-version }} == '7.4' && ${{ matrix.db-type }} == 'mysql' ]]; then
85+
vendor/bin/phpunit --coverage-clover=coverage.xml
86+
else
87+
vendor/bin/phpunit
88+
fi
89+
90+
- name: Code Coverage Report
91+
if: success() && matrix.php-version == '7.4' && matrix.db-type == 'mysql'
92+
uses: codecov/codecov-action@v1
93+
94+
cs-stan:
95+
name: Coding Standard & Static Analysis
96+
runs-on: ubuntu-18.04
97+
98+
steps:
99+
- uses: actions/checkout@v1
100+
with:
101+
fetch-depth: 1
102+
103+
- name: Setup PHP
104+
uses: shivammathur/setup-php@v2
105+
with:
106+
php-version: '7.4'
107+
extensions: mbstring, intl
108+
coverage: none
109+
tools: psalm:~4.1.0
110+
111+
- name: Composer Install
112+
run: composer install
113+
114+
- name: Run phpcs
115+
run: vendor/bin/phpcs -p src/ tests/
116+
117+
- name: Run psalm
118+
run: psalm --output-format=github

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"require-dev": {
3333
"cakephp/cakephp-codesniffer": "^4.0",
3434
"cakephp/authorization": "^2.0",
35-
"phpunit/phpunit": "^8.0"
35+
"phpunit/phpunit": "^8.5"
3636
},
3737
"autoload": {
3838
"psr-4": {

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@
3333
<php>
3434
<ini name="memory_limit" value="-1"/>
3535
<!-- Postgres
36-
<env name="db_dsn" value="postgres://root@localhost/cake_test_db"/>
36+
<env name="DB_URL" value="postgres://root@localhost/cake_test_db"/>
3737
-->
3838
<!-- Mysql
39-
<env name="db_dsn" value="mysql://root@localhost/cake_test_db"/>
39+
<env name="DB_URL" value="mysql://root@localhost/cake_test_db"/>
4040
-->
4141
</php>
4242
</phpunit>

src/Command/BenchmarkCommand.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function execute(Arguments $args, ConsoleIo $io): ?int
7575
/**
7676
* Prints calculated results
7777
*
78-
* @param array $times Array of time values
78+
* @param float[] $times Array of time values
7979
* @return void
8080
*/
8181
protected function _results($times)
@@ -89,21 +89,23 @@ protected function _results($times)
8989
$this->io->out('');
9090

9191
$this->io->out(Text::insert(__d('debug_kit', 'Requests/Second: :rps req/sec'), [
92-
'rps' => round($requests / $duration, 3),
92+
'rps' => round($requests / $duration, 3),
9393
]));
9494

9595
$this->io->out(Text::insert(__d('debug_kit', 'Average request time: :average-time seconds'), [
96-
'average-time' => round($duration / $requests, 3),
96+
'average-time' => round($duration / $requests, 3),
9797
]));
9898

9999
$this->io->out(Text::insert(__d('debug_kit', 'Standard deviation of average request time: :std-dev'), [
100-
'std-dev' => round($this->_deviation($times, true), 3),
100+
'std-dev' => round($this->_deviation($times, true), 3),
101101
]));
102102

103-
$this->io->out(Text::insert(__d('debug_kit', 'Longest/shortest request: :longest sec/:shortest sec'), [
103+
if (!empty($times)) {
104+
$this->io->out(Text::insert(__d('debug_kit', 'Longest/shortest request: :longest sec/:shortest sec'), [
104105
'longest' => round(max($times), 3),
105106
'shortest' => round(min($times), 3),
106-
]));
107+
]));
108+
}
107109

108110
$this->io->out('');
109111
}

tests/Fixture/PanelsFixture.php

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,7 @@ class PanelsFixture extends TestFixture
6060
*
6161
* @var array
6262
*/
63-
public $records = [
64-
[
65-
'id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
66-
'request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
67-
'panel' => 'DebugKit.Request',
68-
'title' => 'Request',
69-
'element' => 'DebugKit.request_panel',
70-
'content' => 'a:5:{s:6:"params";a:5:{s:6:"plugin";N;s:10:"controller";s:5:"Tasks";s:6:"action";s:3:"add";s:4:"_ext";N;s:4:"pass";a:0:{}}s:5:"query";a:0:{}s:4:"data";a:0:{}s:6:"cookie";a:2:{s:14:"toolbarDisplay";s:4:"show";s:7:"CAKEPHP";s:26:"9pk8sa2ot6pclki9f4iakio560";}s:3:"get";a:0:{}}',
71-
],
72-
];
63+
public $records = [];
7364

7465
/**
7566
* Constructor

tests/Fixture/RequestsFixture.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,7 @@ class RequestsFixture extends TestFixture
5252
*
5353
* @var array
5454
*/
55-
public $records = [
56-
[
57-
'id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
58-
'url' => '/tasks/add',
59-
'content_type' => 'text/html',
60-
'status_code' => 200,
61-
'requested_at' => '2014-08-21 7:41:12',
62-
],
63-
];
55+
public $records = [];
6456

6557
/**
6658
* Constructor

tests/TestCase/Controller/DashboardControllerTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
namespace DebugKit\Test\TestCase\Controller;
1717

1818
use Cake\TestSuite\IntegrationTestCase;
19+
use DebugKit\Test\TestCase\FixtureFactoryTrait;
1920
use DebugKit\TestApp\Application;
2021

2122
/**
2223
* Dashboard controller test.
2324
*/
2425
class DashboardControllerTest extends IntegrationTestCase
2526
{
27+
use FixtureFactoryTrait;
28+
2629
public $fixtures = [
2730
'plugin.DebugKit.Requests',
2831
'plugin.DebugKit.Panels',
@@ -37,7 +40,6 @@ public function setUp(): void
3740
{
3841
parent::setUp();
3942
$this->configApplication(Application::class, []);
40-
$this->useHttpServer(true);
4143
}
4244

4345
public function testIndexNoRequests()
@@ -55,9 +57,8 @@ public function testIndexNoRequests()
5557

5658
public function testIndexWithRequests()
5759
{
58-
$requests = $this->getTableLocator()->get('DebugKit.Requests');
59-
$request = $requests->newEntity(['url' => '/example']);
60-
$requests->save($request);
60+
$request = $this->makeRequest();
61+
$this->makePanel($request);
6162

6263
$this->get('/debug-kit/dashboard');
6364

@@ -68,12 +69,13 @@ public function testIndexWithRequests()
6869

6970
public function testReset()
7071
{
71-
$requests = $this->getTableLocator()->get('DebugKit.Requests');
72-
$this->assertGreaterThan(0, $requests->find()->count(), 'precondition failed');
72+
$request = $this->makeRequest();
73+
$this->makePanel($request);
7374

7475
$this->post('/debug-kit/dashboard/reset');
7576

7677
$this->assertRedirect('/debug-kit');
78+
$requests = $this->getTableLocator()->get('DebugKit.Requests');
7779
$this->assertSame(0, $requests->find()->count());
7880
}
7981
}

tests/TestCase/Controller/MailPreviewControllerTest.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@
1717

1818
use Cake\Routing\Router;
1919
use Cake\TestSuite\IntegrationTestCase;
20+
use DebugKit\Test\TestCase\FixtureFactoryTrait;
2021
use DebugKit\TestApp\Application;
2122

2223
/**
2324
* Mail preview controller test
2425
*/
2526
class MailPreviewControllerTest extends IntegrationTestCase
2627
{
28+
use FixtureFactoryTrait;
29+
2730
/**
2831
* Fixtures.
2932
*
@@ -46,7 +49,6 @@ public function setUp(): void
4649
$routes->connect('/users/:action/*', ['controller' => 'Users']);
4750
});
4851
$this->configApplication(Application::class, []);
49-
$this->useHttpServer(true);
5052
}
5153

5254
/**
@@ -105,8 +107,9 @@ public function testSentInvalidData()
105107
*/
106108
public function testSentValidData()
107109
{
108-
$panels = $this->getTableLocator()->get('Panels');
109-
$panel = $panels->newEntity(['request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']);
110+
$panels = $this->getTableLocator()->get('DebugKit.Panels');
111+
$request = $this->makeRequest();
112+
$panel = $panels->newEntity(['request_id' => $request->id]);
110113
$data = [
111114
'emails' => [
112115
[
@@ -131,8 +134,9 @@ public function testSentValidData()
131134
*/
132135
public function testSentValidDataRenderPart()
133136
{
134-
$panels = $this->getTableLocator()->get('Panels');
135-
$panel = $panels->newEntity(['request_id' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa']);
137+
$panels = $this->getTableLocator()->get('DebugKit.Panels');
138+
$request = $this->makeRequest();
139+
$panel = $panels->newEntity(['request_id' => $request->id]);
136140
$data = [
137141
'emails' => [
138142
[

tests/TestCase/Controller/PanelsControllerTest.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,16 @@
1616
namespace DebugKit\Test\TestCase\Controller;
1717

1818
use Cake\TestSuite\IntegrationTestCase;
19+
use DebugKit\Test\TestCase\FixtureFactoryTrait;
1920
use DebugKit\TestApp\Application;
2021

2122
/**
2223
* Panel controller test.
2324
*/
2425
class PanelsControllerTest extends IntegrationTestCase
2526
{
27+
use FixtureFactoryTrait;
28+
2629
/**
2730
* Fixtures.
2831
*
@@ -42,7 +45,6 @@ public function setUp(): void
4245
{
4346
parent::setUp();
4447
$this->configApplication(Application::class, []);
45-
$this->useHttpServer(true);
4648
}
4749

4850
/**
@@ -57,8 +59,9 @@ public function testIndex()
5759
'accept' => 'application/json, text/javascript, */*; q=0.01',
5860
],
5961
]);
60-
61-
$this->get('/debug-kit/panels/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
62+
$request = $this->makeRequest();
63+
$this->makePanel($request);
64+
$this->get("/debug-kit/panels/{$request->id}");
6265

6366
$this->assertResponseOk();
6467
$this->assertContentType('application/json');
@@ -71,7 +74,10 @@ public function testIndex()
7174
*/
7275
public function testView()
7376
{
74-
$this->get('/debug-kit/panels/view/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa');
77+
$request = $this->makeRequest();
78+
$panel = $this->makePanel($request);
79+
80+
$this->get("/debug-kit/panels/view/{$panel->id}");
7581

7682
$this->assertResponseOk();
7783
$this->assertResponseContains('Request</h2>');

0 commit comments

Comments
 (0)