1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-23 17:12:41 +00:00
Arsse/tests/lib/Lang/Setup.php

63 lines
2.5 KiB
PHP
Raw Normal View History

2017-02-06 00:00:57 +00:00
<?php
/** @license MIT
* Copyright 2017 J. King, Dustin Wilson et al.
* See LICENSE and AUTHORS files for details */
2017-02-06 00:00:57 +00:00
declare(strict_types=1);
2017-03-28 04:12:12 +00:00
namespace JKingWeb\Arsse\Test\Lang;
2017-08-29 14:50:31 +00:00
use JKingWeb\Arsse\Lang;
use JKingWeb\Arsse\Arsse;
use org\bovigo\vfs\vfsStream;
use Phake;
2017-02-06 00:00:57 +00:00
trait Setup {
2017-08-29 14:50:31 +00:00
public function setUp() {
2017-02-16 20:29:42 +00:00
// test files
$this->files = [
2017-02-16 20:29:42 +00:00
'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"];',
2017-02-16 20:29:42 +00:00
// 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()."/";
2017-02-16 20:29:42 +00:00
// 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 TestLang($this->path);
// create a mock Lang object so as not to create a dependency loop
2018-11-23 15:01:17 +00:00
self::clearData(false);
Arsse::$lang = Phake::mock(Lang::class);
Phake::when(Arsse::$lang)->msg->thenReturn("");
// call the additional setup method if it exists
2017-08-29 14:50:31 +00:00
if (method_exists($this, "setUpSeries")) {
$this->setUpSeries();
}
2017-02-16 20:29:42 +00:00
}
2017-08-29 14:50:31 +00:00
public function tearDown() {
// verify calls to the mock Lang object
Phake::verify(Arsse::$lang, Phake::atLeast(0))->msg($this->isType("string"), $this->anything());
Phake::verifyNoOtherInteractions(Arsse::$lang);
// clean up
2018-11-23 15:01:17 +00:00
self::clearData(true);
// call the additional teardiwn method if it exists
2017-08-29 14:50:31 +00:00
if (method_exists($this, "tearDownSeries")) {
$this->tearDownSeries();
}
2017-02-16 20:29:42 +00:00
}
2017-08-29 14:50:31 +00:00
}