Page MenuHomeDevCentral

ConfigValidateTest.php
No OneTemporary

ConfigValidateTest.php

<?php
namespace Nasqueron\Notifications\Tests\Console\Commands;
use Storage;
class ConfigValidateTest extends TestCase {
/**
* @var string
*/
protected $class = 'Nasqueron\Notifications\Console\Commands\ConfigValidate';
const TEST_FILE = 'bug.json';
public function testRegularExecute () {
$this->tester->execute(['command' => $this->command->getName()]);
// When all files are valid, nothing is displayed
$this->assertEquals('', $this->tester->getDisplay());
}
/**
* @dataProvider provideErrors
*/
public function testSyntaxErrorExecute (string $content, string $error) {
$this->populateTestFile($content); // Not JSON
$this->tester->execute(['command' => $this->command->getName()]);
// When all files are valid, nothing is displayed
$this->assertRegexp("/$error/", $this->tester->getDisplay());
}
/**
* Provides invalid JSON strings and associated error
*/
public function provideErrors () : array {
return [
["lorem ipsum dolor", "Syntax error"],
['{"}', "Control character error"]
];
}
private function populateTestFile (string $content) : void {
Storage::disk('local')->put(self::TEST_FILE, $content);
}
private function deleteTestFile () : void {
$fs = Storage::disk('local');
if ($fs->exists(self::TEST_FILE)) {
$fs->delete(self::TEST_FILE);
}
}
public function tearDown () {
$this->deleteTestFile();
parent::tearDown();
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Feb 28, 21:39 (1 d, 5 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2437487
Default Alt Text
ConfigValidateTest.php (1 KB)

Event Timeline