for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* This file is part of CaptainHook.
*
* (c) Sebastian Feldmann <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CaptainHook\App\Storage\File;
use Exception;
use PHPUnit\Framework\TestCase;
class JsonTest extends TestCase
{
* Tests Json::readAssoc
public function testReadInvalid(): void
$this->expectException(Exception::class);
$path = realpath(CH_PATH_FILES . '/config/invalid.json');
$json = new Json($path);
$data = $json->readAssoc();
$data
}
public function testReadAssoc(): void
$path = realpath(CH_PATH_FILES . '/storage/test.json');
$this->assertEquals('bar', $data['foo']);
* Test Json::write
public function testWrite(): void
$path = tempnam(sys_get_temp_dir(), 'json');
$data = ['foo' => 'bar'];
$json->write($data);
$json = file_get_contents($path);
$load = json_decode($json, true);
unlink($path);
$this->assertEquals('bar', $load['foo']);