Skip to content

Commit da0cc7a

Browse files
committed
Update testing
Signed-off-by: Matt Friedman <maf675@gmail.com>
1 parent bb19ee6 commit da0cc7a

2 files changed

Lines changed: 101 additions & 1 deletion

File tree

.github/workflows/tests.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
strategy:
2626
matrix:
2727
include:
28-
- php: '7.1'
28+
- php: '7.2'
2929
db: "none"
3030
NOTESTS: 1
3131

@@ -123,6 +123,8 @@ jobs:
123123
db: "mysql:5.7"
124124
- php: '8.1'
125125
db: "mysql:5.7"
126+
- php: '8.2'
127+
db: "mysql:5.7"
126128

127129
name: PHP ${{ matrix.php }} - ${{ matrix.db_alias != '' && matrix.db_alias || matrix.db }}
128130

@@ -221,6 +223,20 @@ jobs:
221223
db: "postgres:12"
222224
- php: '7.1'
223225
db: "postgres:13"
226+
- php: '7.2'
227+
db: "postgres:13"
228+
- php: '7.3'
229+
db: "postgres:13"
230+
- php: '7.4'
231+
db: "postgres:13"
232+
- php: '8.0'
233+
db: "postgres:12"
234+
- php: '8.0'
235+
db: "postgres:13"
236+
- php: '8.1'
237+
db: "postgres:14"
238+
- php: '8.2'
239+
db: "postgres:14"
224240

225241
name: PHP ${{ matrix.php }} - ${{ matrix.db }}
226242

tests/cron/cron_test.php

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
/**
3+
*
4+
* Ideas extension for the phpBB Forum Software package.
5+
*
6+
* @copyright (c) phpBB Limited <https://www.phpbb.com>
7+
* @license GNU General Public License, version 2 (GPL-2.0)
8+
*
9+
*/
10+
11+
namespace phpbb\ideas\tests\cron;
12+
13+
class cron_test extends \phpbb_test_case
14+
{
15+
/** @var \phpbb\config\config */
16+
protected $config;
17+
18+
/** @var \phpbb\ideas\cron\prune_orphaned_ideas */
19+
protected $cron_task;
20+
21+
/** @var \phpbb\ideas\factory\ideas|\PHPUnit\Framework\MockObject\MockObject */
22+
protected $ideas;
23+
24+
protected function setUp(): void
25+
{
26+
parent::setUp();
27+
28+
$this->config = new \phpbb\config\config(['ideas_cron_last_run' => 0]);
29+
30+
$this->ideas = $this->getMockBuilder('\phpbb\ideas\factory\ideas')
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$this->cron_task = new \phpbb\ideas\cron\prune_orphaned_ideas($this->config, $this->ideas);
35+
}
36+
37+
/**
38+
* Test the cron task runs correctly
39+
*/
40+
public function test_run()
41+
{
42+
// Get last run time stored for cron
43+
$cron_last_run = $this->config['ideas_cron_last_run'];
44+
45+
// Expect ideas method delete_orphans is called once
46+
$this->ideas->expects(self::once())
47+
->method('delete_orphans');
48+
49+
// Run the cron task
50+
$this->cron_task->run();
51+
52+
// Now the last run time should be greater than before the test
53+
self::assertGreaterThan($cron_last_run, $this->config['ideas_cron_last_run']);
54+
}
55+
56+
/**
57+
* Data set for test_should_run
58+
*
59+
* @return array Array of test data
60+
*/
61+
public function should_run_data()
62+
{
63+
return array(
64+
array(time(), false),
65+
array(strtotime('1 day ago'), false),
66+
array(strtotime('8 days ago'), true),
67+
array('', true),
68+
array(0, true),
69+
array(null, true),
70+
);
71+
}
72+
73+
/**
74+
* Test cron task should run after 1 week (7 days)
75+
*
76+
* @dataProvider should_run_data
77+
*/
78+
public function test_should_run($time, $expected)
79+
{
80+
$this->config['ideas_cron_last_run'] = $time;
81+
82+
self::assertSame($expected, $this->cron_task->should_run());
83+
}
84+
}

0 commit comments

Comments
 (0)