First unit tests, add a few of the forgotten app requirements

This commit is contained in:
Timothy Warren 2015-06-25 17:00:29 -04:00
parent 185315c716
commit 0b63f810a9
11 changed files with 201 additions and 25 deletions

2
.gitignore vendored
View File

@ -6,3 +6,5 @@ composer.lock
*.sqlite *.sqlite
*.db *.db
*.sqlite3 *.sqlite3
docs/*
coverage/*

12
.travis.yml Normal file
View File

@ -0,0 +1,12 @@
language: php
install:
- composer install
php:
- 5.4
- 5.5
- 5.6
- 7
- hhvm
- nightly

View File

@ -30,6 +30,7 @@ A self-hosted client that allows custom formatting of data from the hummingbird
* PHP 5.4+ * PHP 5.4+
* PDO SQLite (For collection tab) * PDO SQLite (For collection tab)
* GD
### Installation ### Installation

View 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;
}
}
});
}

View File

@ -115,6 +115,9 @@ class MangaModel extends BaseApiModel {
file_put_contents($cache_file, json_encode($raw_data)); 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 = [ $data = [
'Reading' => [], 'Reading' => [],
'Plan to Read' => [], 'Plan to Read' => [],

View File

@ -3,43 +3,38 @@
* Here begins everything! * Here begins everything!
*/ */
// -----------------------------------------------------------------------------
// ! Start config
// -----------------------------------------------------------------------------
/** /**
* Well, whose list is it? * Well, whose list is it?
*/ */
define('WHOSE', "Tim's"); define('WHOSE', "Tim's");
/** // -----------------------------------------------------------------------------
* Joins paths together. Variadic to take an // ! End config
* arbitrary number of arguments // -----------------------------------------------------------------------------
*
* @return string // Work around the silly timezone error
*/ $timezone = ini_get('date.timezone');
function _dir() { return implode(DIRECTORY_SEPARATOR, func_get_args()); } if ($timezone === '' || $timezone === FALSE)
{
ini_set('date.timezone', 'GMT');
}
define('ROOT_DIR', __DIR__); define('ROOT_DIR', __DIR__);
define('APP_DIR', _dir(ROOT_DIR, 'app')); define('APP_DIR', ROOT_DIR . DIRECTORY_SEPARATOR . 'app');
define('CONF_DIR', _dir(APP_DIR, 'config')); define('CONF_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'config');
define('BASE_DIR', _dir(APP_DIR, 'base')); define('BASE_DIR', APP_DIR . DIRECTORY_SEPARATOR . 'base');
require BASE_DIR . DIRECTORY_SEPARATOR . 'pre_conf_functions.php';
// Load config and global functions // Load config and global functions
$config = require _dir(APP_DIR, '/config/config.php'); $config = require _dir(APP_DIR, '/config/config.php');
require _dir(BASE_DIR, '/functions.php'); require _dir(BASE_DIR, '/functions.php');
// Setup autoloaders // Setup autoloaders
require _dir(ROOT_DIR, '/vendor/autoload.php'); _setup_autoloaders();
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;
}
}
});
session_start(); session_start();

23
phpdoc.dist.xml Normal file
View 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
View 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
View 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));
}
}

View 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
View 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