BrowscapTest\Data\DataCollectionTest::testAddEnginesFileThrowsExceptionIfFileContainsInvalidJson PHP Метод

testAddEnginesFileThrowsExceptionIfFileContainsInvalidJson() публичный Метод

tests if a specific exception is thrown in case of error while adding an engine json file
    public function testAddEnginesFileThrowsExceptionIfFileContainsInvalidJson()
    {
        $tmpfile = tempnam(sys_get_temp_dir(), 'browscaptest');
        $in = <<<HERE
this is not valid JSON
HERE;
        file_put_contents($tmpfile, $in);
        $fail = false;
        $message = '';
        try {
            $this->object->addEnginesFile($tmpfile);
            $fail = true;
            $message = 'expected Exception "\\RuntimeException" not thrown, no exception thrown';
        } catch (\RuntimeException $ex) {
            if ('File "' . $tmpfile . '" had invalid JSON.' !== $ex->getMessage()) {
                $fail = true;
                $message = 'expected Message \'File "' . $tmpfile . '" had invalid JSON.\' not available, the message was "' . $ex->getMessage() . '"';
            }
        } catch (\Exception $ex) {
            $fail = true;
            $message = 'expected Exception "\\RuntimeException" not thrown, Exception ' . get_class($ex) . ' thrown';
        }
        unlink($tmpfile);
        if ($fail) {
            $this->fail($message);
        }
    }
DataCollectionTest