string("it's \"a\" test")->getSource(); $this->assertStringNotContainsString("'", $source); $this->assertSame('"it\\x27s \\"a\\" test"', $source); $decoded = null; eval('$decoded = '.$source.';'); $this->assertSame("it's \"a\" test", $decoded); } public function testReprNumericValueWithLocale(): void { $compiler = new Compiler(new Environment(new ArrayLoader())); $locale = setlocale(\LC_NUMERIC, '0'); if (false === $locale) { $this->markTestSkipped('Your platform does not support locales.'); } $required_locales = ['fr_FR.UTF-8', 'fr_FR.UTF8', 'fr_FR.utf-8', 'fr_FR.utf8', 'French_France.1252']; if (false === setlocale(\LC_NUMERIC, $required_locales)) { $this->markTestSkipped('Could not set any of required locales: '.implode(', ', $required_locales)); } $this->assertEquals('1.2', $compiler->repr(1.2)->getSource()); $this->assertStringContainsString('fr', strtolower(setlocale(\LC_NUMERIC, '0'))); setlocale(\LC_NUMERIC, $locale); } public function testReprFloatDoesNotDependOnSerializePrecision(): void { $compiler = new Compiler(new Environment(new ArrayLoader())); $precision = ini_set('serialize_precision', '17'); try { $this->assertSame('0.1', $compiler->repr(0.1)->getSource()); $this->assertSame('17', \ini_get('serialize_precision')); } finally { ini_set('serialize_precision', $precision); } } }