First unit tests, add a few of the forgotten app requirements
This commit is contained in:
parent
185315c716
commit
0b63f810a9
4
.gitignore
vendored
4
.gitignore
vendored
@ -5,4 +5,6 @@ public/js/cache/*
|
||||
composer.lock
|
||||
*.sqlite
|
||||
*.db
|
||||
*.sqlite3
|
||||
*.sqlite3
|
||||
docs/*
|
||||
coverage/*
|
12
.travis.yml
Normal file
12
.travis.yml
Normal file
@ -0,0 +1,12 @@
|
||||
language: php
|
||||
|
||||
install:
|
||||
- composer install
|
||||
|
||||
php:
|
||||
- 5.4
|
||||
- 5.5
|
||||
- 5.6
|
||||
- 7
|
||||
- hhvm
|
||||
- nightly
|
@ -30,6 +30,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
|
||||
|
||||
* PHP 5.4+
|
||||
* PDO SQLite (For collection tab)
|
||||
* GD
|
||||
|
||||
### Installation
|
||||
|
||||
|
40
app/base/pre_conf_functions.php
Normal file
40
app/base/pre_conf_functions.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Functions that need to be included before config
|
||||
*/
|
||||
|
||||
/**
|
||||
* Joins paths together. Variadic to take an
|
||||
* arbitrary number of arguments
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _dir()
|
||||
{
|
||||
return implode(DIRECTORY_SEPARATOR, func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up autoloaders
|
||||
*
|
||||
* @codeCoverageIgnore
|
||||
* @return void
|
||||
*/
|
||||
function _setup_autoloaders()
|
||||
{
|
||||
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
||||
spl_autoload_register(function ($class) {
|
||||
$dirs = ["base", "controllers", "models"];
|
||||
|
||||
foreach($dirs as $dir)
|
||||
{
|
||||
$file = _dir(APP_DIR, $dir, "{$class}.php");
|
||||
if (file_exists($file))
|
||||
{
|
||||
require_once $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
@ -115,6 +115,9 @@ class MangaModel extends BaseApiModel {
|
||||
file_put_contents($cache_file, json_encode($raw_data));
|
||||
}
|
||||
|
||||
// Bail out early if there isn't any manga data
|
||||
if (empty($raw_data)) return [];
|
||||
|
||||
$data = [
|
||||
'Reading' => [],
|
||||
'Plan to Read' => [],
|
||||
|
43
index.php
43
index.php
@ -3,43 +3,38 @@
|
||||
* Here begins everything!
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// ! Start config
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Well, whose list is it?
|
||||
*/
|
||||
define('WHOSE', "Tim's");
|
||||
|
||||
/**
|
||||
* Joins paths together. Variadic to take an
|
||||
* arbitrary number of arguments
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
function _dir() { return implode(DIRECTORY_SEPARATOR, func_get_args()); }
|
||||
// -----------------------------------------------------------------------------
|
||||
// ! End config
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Work around the silly timezone error
|
||||
$timezone = ini_get('date.timezone');
|
||||
if ($timezone === '' || $timezone === FALSE)
|
||||
{
|
||||
ini_set('date.timezone', 'GMT');
|
||||
}
|
||||
|
||||
define('ROOT_DIR', __DIR__);
|
||||
define('APP_DIR', _dir(ROOT_DIR, 'app'));
|
||||
define('CONF_DIR', _dir(APP_DIR, 'config'));
|
||||
define('BASE_DIR', _dir(APP_DIR, 'base'));
|
||||
define('APP_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'app');
|
||||
define('CONF_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'config');
|
||||
define('BASE_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'base');
|
||||
require BASE_DIR . DIRECTORY_SEPARATOR . 'pre_conf_functions.php';
|
||||
|
||||
// Load config and global functions
|
||||
$config = require _dir(APP_DIR, '/config/config.php');
|
||||
require _dir(BASE_DIR, '/functions.php');
|
||||
|
||||
// Setup autoloaders
|
||||
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
||||
spl_autoload_register(function ($class) {
|
||||
$dirs = ["base", "controllers", "models"];
|
||||
|
||||
foreach($dirs as $dir)
|
||||
{
|
||||
$file = _dir(APP_DIR, $dir, "{$class}.php");
|
||||
if (file_exists($file))
|
||||
{
|
||||
require_once $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
});
|
||||
_setup_autoloaders();
|
||||
|
||||
session_start();
|
||||
|
||||
|
23
phpdoc.dist.xml
Normal file
23
phpdoc.dist.xml
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<phpdoc>
|
||||
<title>Hummingbird Anime Client</title>
|
||||
<parser>
|
||||
<target>docs</target>
|
||||
</parser>
|
||||
<transformer>
|
||||
<target>docs</target>
|
||||
</transformer>
|
||||
<transformations>
|
||||
<template name="clean" />
|
||||
</transformations>
|
||||
<files>
|
||||
<directory>.</directory>
|
||||
<directory>app</directory>
|
||||
<ignore>public/*</ignore>
|
||||
<ignore>app/views/*</ignore>
|
||||
<ignore>app/config/*</ignore>
|
||||
<ignore>migrations/*</ignore>
|
||||
<ignore>tests/*</ignore>
|
||||
<ignore>vendor/*</ignore>
|
||||
</files>
|
||||
</phpdoc>
|
16
phpunit.xml
Normal file
16
phpunit.xml
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit
|
||||
colors="true"
|
||||
stopOnFailure="false"
|
||||
bootstrap="tests/bootstrap.php">
|
||||
<filter>
|
||||
<whitelist>
|
||||
<directory suffix=".php">app</directory>
|
||||
</whitelist>
|
||||
</filter>
|
||||
<testsuites>
|
||||
<testsuite name="BaseTests">
|
||||
<directory>tests/base</directory>
|
||||
</testsuite>
|
||||
</testsuites>
|
||||
</phpunit>
|
22
tests/base/CoreTest.php
Normal file
22
tests/base/CoreTest.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
class CoreTest extends AnimeClient_TestCase {
|
||||
|
||||
public function testPHPVersion()
|
||||
{
|
||||
$this->assertTrue(version_compare(PHP_VERSION, "5.4", "ge"));
|
||||
}
|
||||
|
||||
public function testRequirements()
|
||||
{
|
||||
// Check required extensions
|
||||
$this->assertTrue(extension_loaded('gd'));
|
||||
$this->assertTrue(extension_loaded('mcrypt'));
|
||||
|
||||
// Check for pdo_sqlite
|
||||
$this->assertTrue(class_exists('PDO'));
|
||||
$drivers = PDO::getAvailableDrivers();
|
||||
$this->assertTrue(in_array('sqlite', $drivers));
|
||||
}
|
||||
|
||||
}
|
23
tests/base/FunctionsTest.php
Normal file
23
tests/base/FunctionsTest.php
Normal file
@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
class FunctionsTest extends AnimeClient_TestCase {
|
||||
|
||||
/**
|
||||
* Basic sanity test for _dir function
|
||||
*/
|
||||
public function testDir()
|
||||
{
|
||||
$this->assertEquals('foo'.DIRECTORY_SEPARATOR.'bar', _dir('foo', 'bar'));
|
||||
}
|
||||
|
||||
public function testIsSelected()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function testIsNotSelected()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
39
tests/bootstrap.php
Normal file
39
tests/bootstrap.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
/**
|
||||
* Global setup for unit tests
|
||||
*/
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Mock the default error handler
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
class MockErrorHandler {
|
||||
public function addDataTable($name, Array $values) {}
|
||||
}
|
||||
|
||||
$defaultHandler = new MockErrorHandler();
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Define a base testcase class
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Base class for TestCases
|
||||
*/
|
||||
class AnimeClient_TestCase extends PHPUnit_Framework_TestCase {}
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Autoloaders
|
||||
// -----------------------------------------------------------------------------
|
||||
|
||||
// Define base path constants
|
||||
define('ROOT_DIR', realpath(__DIR__ . DIRECTORY_SEPARATOR . "/../"));
|
||||
require ROOT_DIR . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'base' . DIRECTORY_SEPARATOR . 'pre_conf_functions.php';
|
||||
define('APP_DIR', _dir(ROOT_DIR, 'app'));
|
||||
define('CONF_DIR', _dir(APP_DIR, 'config'));
|
||||
define('BASE_DIR', _dir(APP_DIR, 'base'));
|
||||
|
||||
// Setup autoloaders
|
||||
_setup_autoloaders();
|
||||
|
||||
// End of bootstrap.php
|
Loading…
Reference in New Issue
Block a user