1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Refactor test infrastructure to use PSR-4.

This commit is contained in:
J. King 2017-02-14 22:34:08 -05:00
parent e44ba18d2d
commit 8e2a2c46b1
10 changed files with 35 additions and 88 deletions

View file

@ -19,7 +19,6 @@
], ],
"require": { "require": {
"php": "^7.0.0", "php": "^7.0.0",
"simplepie/simplepie": "^1.4.3",
"jkingweb/druuid": "^3.0.0", "jkingweb/druuid": "^3.0.0",
"phpseclib/phpseclib": "^2.0.4", "phpseclib/phpseclib": "^2.0.4",
"webmozart/glob": "^4.1.0" "webmozart/glob": "^4.1.0"
@ -31,5 +30,10 @@
"psr-4": { "psr-4": {
"JKingWeb\\NewsSync\\": "lib/" "JKingWeb\\NewsSync\\": "lib/"
} }
},
"autoload-dev": {
"psr-4": {
"JKingWeb\\NewsSync\\Test\\": "tests/lib/"
}
} }
} }

62
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "334e725a6288a04515ca881b049ff2eb", "content-hash": "9170a3eabb0743990fa49f653a346eee",
"packages": [ "packages": [
{ {
"name": "jkingweb/druuid", "name": "jkingweb/druuid",
@ -143,66 +143,6 @@
], ],
"time": "2016-10-04T00:57:04+00:00" "time": "2016-10-04T00:57:04+00:00"
}, },
{
"name": "simplepie/simplepie",
"version": "1.4.3",
"source": {
"type": "git",
"url": "https://github.com/simplepie/simplepie.git",
"reference": "2a24b6e74aa9bf33243020f52895fe77efe94ccf"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/simplepie/simplepie/zipball/2a24b6e74aa9bf33243020f52895fe77efe94ccf",
"reference": "2a24b6e74aa9bf33243020f52895fe77efe94ccf",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4 || ~5"
},
"suggest": {
"mf2/mf2": "Microformat module that allows for parsing HTML for microformats"
},
"type": "library",
"autoload": {
"psr-0": {
"SimplePie": "library"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Ryan Parman",
"homepage": "http://ryanparman.com/",
"role": "Creator, alumnus developer"
},
{
"name": "Geoffrey Sneddon",
"homepage": "http://gsnedders.com/",
"role": "Alumnus developer"
},
{
"name": "Ryan McCue",
"email": "me@ryanmccue.info",
"homepage": "http://ryanmccue.info/",
"role": "Developer"
}
],
"description": "A simple Atom/RSS parsing library for PHP",
"homepage": "http://simplepie.org/",
"keywords": [
"atom",
"feeds",
"rss"
],
"time": "2016-11-27T01:39:18+00:00"
},
{ {
"name": "webmozart/assert", "name": "webmozart/assert",
"version": "1.2.0", "version": "1.2.0",

View file

@ -5,7 +5,7 @@ use \org\bovigo\vfs\vfsStream;
class TestConf extends \PHPUnit\Framework\TestCase { class TestConf extends \PHPUnit\Framework\TestCase {
use TestingHelpers; use Test\Tools;
static $vfs; static $vfs;
static $path; static $path;
@ -100,7 +100,6 @@ class TestConf extends \PHPUnit\Framework\TestCase {
*/ */
function testImportFromCorruptFile() { function testImportFromCorruptFile() {
$this->assertException("fileCorrupt", "Conf"); $this->assertException("fileCorrupt", "Conf");
// this should not print the output of the non-PHP file
$conf = new Conf(self::$path."confCorrupt"); $conf = new Conf(self::$path."confCorrupt");
} }
} }

View file

@ -4,7 +4,7 @@ namespace JKingWeb\NewsSync;
class TestException extends \PHPUnit\Framework\TestCase { class TestException extends \PHPUnit\Framework\TestCase {
use TestingHelpers; use Test\Tools;
static function setUpBeforeClass() { static function setUpBeforeClass() {
Lang::set(""); Lang::set("");

View file

@ -5,7 +5,7 @@ use \org\bovigo\vfs\vfsStream;
class TestLang extends \PHPUnit\Framework\TestCase { class TestLang extends \PHPUnit\Framework\TestCase {
use TestingHelpers, LanguageTestingHelpers; use Test\Tools, Test\Lang\Setup;
static $vfs; static $vfs;
static $path; static $path;

View file

@ -5,7 +5,7 @@ use \org\bovigo\vfs\vfsStream;
class TestLangErrors extends \PHPUnit\Framework\TestCase { class TestLangErrors extends \PHPUnit\Framework\TestCase {
use TestingHelpers, LanguageTestingHelpers; use Test\Tools, Test\Lang\Setup;
static $vfs; static $vfs;
static $path; static $path;

View file

@ -1,28 +1,14 @@
<?php <?php
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\NewsSync; namespace JKingWeb\NewsSync\Test\Lang;
require_once __DIR__.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."bootstrap.php"; use \org\bovigo\vfs\vfsStream, \JKingWeb\NewsSync\Lang;
use \org\bovigo\vfs\vfsStream;
trait TestingHelpers {
function assertException(string $msg, string $prefix = "", string $type = "Exception") {
$class = NS_BASE . ($prefix !== "" ? str_replace("/", "\\", $prefix) . "\\" : "") . $type;
$msgID = ($prefix !== "" ? $prefix . "/" : "") . $type. ".$msg";
if(array_key_exists($msgID, Exception::CODES)) {
$code = Exception::CODES[$msgID];
} else {
$code = 0;
}
$this->expectException($class);
$this->expectExceptionCode($code);
}
}
trait LanguageTestingHelpers { trait Setup {
static function setUpBeforeClass() { static function setUpBeforeClass() {
// this is required to keep from having exceptions in Lang::msg() in turn calling Lang::msg() and looping // this is required to keep from having exceptions in Lang::msg() in turn calling Lang::msg() and looping
Lang\Exception::$test = true; \JKingWeb\NewsSync\Lang\Exception::$test = true;
// test files // test files
self::$files = [ self::$files = [
'en.php' => '<?php return ["Test.presentText" => "and the Philosopher\'s Stone"];', 'en.php' => '<?php return ["Test.presentText" => "and the Philosopher\'s Stone"];',
@ -51,7 +37,7 @@ trait LanguageTestingHelpers {
} }
static function tearDownAfterClass() { static function tearDownAfterClass() {
Lang\Exception::$test = false; \JKingWeb\NewsSync\Lang\Exception::$test = false;
Lang::$path = self::$defaultPath; Lang::$path = self::$defaultPath;
self::$path = null; self::$path = null;
self::$vfs = null; self::$vfs = null;

18
tests/lib/Tools.php Normal file
View file

@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace JKingWeb\NewsSync\Test;
use \JKingWeb\NewsSync\Exception;
trait Tools {
function assertException(string $msg, string $prefix = "", string $type = "Exception") {
$class = \JKingWeb\NewsSync\NS_BASE . ($prefix !== "" ? str_replace("/", "\\", $prefix) . "\\" : "") . $type;
$msgID = ($prefix !== "" ? $prefix . "/" : "") . $type. ".$msg";
if(array_key_exists($msgID, Exception::CODES)) {
$code = Exception::CODES[$msgID];
} else {
$code = 0;
}
$this->expectException($class);
$this->expectExceptionCode($code);
}
}

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<phpunit <phpunit
colors="true" colors="true"
bootstrap="bootstrap.php" bootstrap="../bootstrap.php"
convertErrorsToExceptions="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" convertWarningsToExceptions="true"

View file

@ -5,7 +5,7 @@ use \org\bovigo\vfs\vfsStream;
class TestLangComplex extends \PHPUnit\Framework\TestCase { class TestLangComplex extends \PHPUnit\Framework\TestCase {
use TestingHelpers, LanguageTestingHelpers; use Test\Tools, Test\Lang\Setup;
static $vfs; static $vfs;
static $path; static $path;