Skip to content

Commit

Permalink
Fix shell code
Browse files Browse the repository at this point in the history
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Mar 2, 2021
1 parent 51c5e19 commit 4cdd2a9
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Controller/StatsController.php
Expand Up @@ -53,7 +53,7 @@ public function stats(): void
$filter_string = 'all_time';
}
$entriesWithCount = [];
//Cache::clear(false);
//Cache::clear();
foreach (TableRegistry::getTableLocator()->get('Incidents')->summarizableFields as $field) {
$entriesWithCount = Cache::read($field . '_' . $filter_string);
if ($entriesWithCount === false) {
Expand Down
33 changes: 30 additions & 3 deletions src/Shell/SyncGithubIssueStatesShell.php
Expand Up @@ -20,8 +20,10 @@

use Cake\Console\Shell;
use Cake\Core\Configure;
use Cake\Core\HttpApplicationInterface;
use Cake\Http\Server;
use Cake\Http\ServerRequest;
use Cake\Log\Log;
use Cake\Routing\Router;
use const PHP_SAPI;
use function date;

Expand All @@ -30,6 +32,23 @@
*/
class SyncGithubIssueStatesShell extends Shell
{
/**
* The application that is being dispatched.
*
* @var HttpApplicationInterface
*/
protected $app;

/**
* Constructor
*
* @param HttpApplicationInterface $app The test case to run.
*/
public function __construct(HttpApplicationInterface $app)
{
$this->app = $app;
}

public function main(): void
{
Log::debug(
Expand All @@ -45,8 +64,16 @@ public function main(): void
exit;
}

//TODO: check if works
Router::connect('github/sync_issue_status');
$request = new ServerRequest([
'url' => '/github/sync_issue_status',
'params' => [
'controller' => 'Github',
'action' => 'sync_issue_status',
],
]);

$server = new Server($this->app);
$server->run($request);

Log::debug(
'FINISHED: Job "'
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase/Shell/StatsShellTest.php
Expand Up @@ -79,7 +79,7 @@ public function testMain(): void
$this->Stats->initialize();

// Clear the existing cache
Cache::clear(false);
Cache::clear();

// Run the shell command
$this->Stats->main();
Expand Down
8 changes: 7 additions & 1 deletion tests/TestCase/Shell/SyncGithubIssueStatesShellTest.php
Expand Up @@ -4,6 +4,7 @@

use App\Shell\SyncGithubIssueStatesShell;
use Cake\Console\ConsoleIo;
use Cake\Http\BaseApplication;
use Cake\ORM\TableRegistry;
use Cake\TestSuite\TestCase;
use phpmock\phpunit\PHPMock;
Expand Down Expand Up @@ -48,7 +49,12 @@ public function setUp(): void
{
parent::setUp();
$this->io = $this->getMockBuilder('Cake\Console\ConsoleIo')->getMock();
$this->SyncGithubIssueStates = new SyncGithubIssueStatesShell($this->io);
/** @var BaseApplication $app */
$app = $this->getMockForAbstractClass(
BaseApplication::class,
[__DIR__ . '/../../../config']
);
$this->SyncGithubIssueStates = new SyncGithubIssueStatesShell($app);
$this->Reports = TableRegistry::getTableLocator()->get('Reports');
}

Expand Down

0 comments on commit 4cdd2a9

Please sign in to comment.