1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 09:02:41 +00:00
Arsse/tests/lib/Lang/Setup.php
J. King f902346b6c Eliminated passing of RuntimeData instances
- RuntimeData has now been replaced by a single static Data class
- The Data class has a load() method which fills the same role as the constructor of RuntimeData
- The static Lang class is now an instantiable class and is a member of Data
- All tests have been adjusted and pass
- The Exception tests no longer require convoluted workarounds: a simple mock  for Data::$l suffices; Lang tests also use a mock to prevent loops now instead of using a workaround
2017-03-28 18:50:00 -04:00

51 lines
No EOL
2.2 KiB
PHP

<?php
declare(strict_types=1);
namespace JKingWeb\Arsse\Test\Lang;
use org\bovigo\vfs\vfsStream;
use JKingWeb\Arsse\Lang;
use JKingWeb\Arsse\Data;
trait Setup {
function setUp() {
// test files
$this->files = [
'en.php' => '<?php return ["Test.presentText" => "and the Philosopher\'s Stone"];',
'en_ca.php' => '<?php return ["Test.presentText" => "{0} and {1}"];',
'en_us.php' => '<?php return ["Test.presentText" => "and the Sorcerer\'s Stone"];',
'fr.php' => '<?php return ["Test.presentText" => "à l\'école des sorciers"];',
'ja.php' => '<?php return ["Test.absentText" => "賢者の石"];',
'de.php' => '<?php return ["Test.presentText" => "und der Stein der Weisen"];',
'pt_br.php' => '<?php return ["Test.presentText" => "e a Pedra Filosofal"];',
// corrupted message in valid file
'vi.php' => '<?php return ["Test.presentText" => "{0} and {1"];',
// corrupt files
'it.php' => '<?php return 0;',
'zh.php' => '<?php return 0',
'ko.php' => 'DEAD BEEF',
'fr_ca.php' => '',
// unreadable file
'ru.php' => '',
];
$vfs = vfsStream::setup("langtest", 0777, $this->files);
$this->path = $vfs->url()."/";
// set up a file without read access
chmod($this->path."ru.php", 0000);
// make the test Lang class use the vfs files
$this->l = new Lang($this->path);
// create a mock Lang object to keep exceptions from creating loops
$this->clearData(false);
$m = $this->getMockBuilder(Lang::class)->setMethods(['__invoke'])->getMock();
$m->expects($this->any())->method("__invoke")->with($this->anything(), $this->anything())->will($this->returnValue(""));
Data::$l = $m;
// call the additional setup method if it exists
if(method_exists($this, "setUpSeries")) $this->setUpSeries();
}
function tearDown() {
$this->clearData(true);
// call the additional teardiwn method if it exists
if(method_exists($this, "tearDownSeries")) $this->tearDownSeries();
}
}