Rearrange some namespaces and add more docblocks
This commit is contained in:
parent
9cf958b1ed
commit
f49e4fe3d8
@ -5,8 +5,6 @@
|
|||||||
use Whoops\Handler\PrettyPageHandler;
|
use Whoops\Handler\PrettyPageHandler;
|
||||||
use Whoops\Handler\JsonResponseHandler;
|
use Whoops\Handler\JsonResponseHandler;
|
||||||
|
|
||||||
use Aviat\AnimeClient\Config;
|
|
||||||
|
|
||||||
// Work around the silly timezone error
|
// Work around the silly timezone error
|
||||||
$timezone = ini_get('date.timezone');
|
$timezone = ini_get('date.timezone');
|
||||||
if ($timezone === '' || $timezone === FALSE)
|
if ($timezone === '' || $timezone === FALSE)
|
||||||
@ -49,7 +47,6 @@ spl_autoload_register(function($class) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Dependency setup
|
|
||||||
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
require _dir(ROOT_DIR, '/vendor/autoload.php');
|
||||||
require _dir(SRC_DIR, '/functions.php');
|
require _dir(SRC_DIR, '/functions.php');
|
||||||
|
|
||||||
@ -67,7 +64,8 @@ $jsonHandler = new JsonResponseHandler();
|
|||||||
$jsonHandler->onlyForAjaxRequests(TRUE);
|
$jsonHandler->onlyForAjaxRequests(TRUE);
|
||||||
$whoops->pushHandler($jsonHandler);
|
$whoops->pushHandler($jsonHandler);
|
||||||
|
|
||||||
//$whoops->register();
|
// Register as the error handler
|
||||||
|
$whoops->register();
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
// Dependency Injection setup
|
// Dependency Injection setup
|
||||||
|
@ -20,7 +20,7 @@ class Config {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param array $config_files
|
* @param array $config_array
|
||||||
*/
|
*/
|
||||||
public function __construct(array $config_array = [])
|
public function __construct(array $config_array = [])
|
||||||
{
|
{
|
||||||
|
@ -7,7 +7,7 @@ namespace Aviat\AnimeClient\Controller;
|
|||||||
|
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
use Aviat\AnimeClient\Controller as BaseController;
|
use Aviat\AnimeClient\Controller as BaseController;
|
||||||
use Aviat\AnimeClient\Enum\Hummingbird\AnimeWatchingStatus;
|
use Aviat\AnimeClient\Hummingbird\Enum\AnimeWatchingStatus;
|
||||||
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
use Aviat\AnimeClient\Model\Anime as AnimeModel;
|
||||||
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
|
use Aviat\AnimeClient\Model\AnimeCollection as AnimeCollectionModel;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ class Collection extends BaseController {
|
|||||||
parent::__construct($container);
|
parent::__construct($container);
|
||||||
|
|
||||||
$this->urlGenerator = $container->get('url-generator');
|
$this->urlGenerator = $container->get('url-generator');
|
||||||
$this->anime_anime_collection_model = new AnimeCollectionModel($container);
|
$this->anime_collection_model = new AnimeCollectionModel($container);
|
||||||
$this->base_data = array_merge($this->base_data, [
|
$this->base_data = array_merge($this->base_data, [
|
||||||
'menu_name' => 'collection',
|
'menu_name' => 'collection',
|
||||||
'message' => '',
|
'message' => '',
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Enum\Hummingbird;
|
|
||||||
|
|
||||||
use Aviat\Ion\Enum;
|
|
||||||
|
|
||||||
class AnimeAgeRating extends Enum {
|
|
||||||
const G = 'G';
|
|
||||||
const PG = 'PG';
|
|
||||||
const PG13 = 'PG13';
|
|
||||||
const R = 'R17+';
|
|
||||||
const X = 'R18+';
|
|
||||||
}
|
|
||||||
// End of AnimeAgeRating.php
|
|
@ -1,12 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Enum\Hummingbird;
|
|
||||||
|
|
||||||
use Aviat\Ion\Enum;
|
|
||||||
|
|
||||||
class AnimeAiringStatus extends Enum {
|
|
||||||
const NOT_YET_AIRED = 'Not Yet Aired';
|
|
||||||
const AIRING = 'Currently Airing';
|
|
||||||
const FINISHED_AIRING = 'Finished Airing';
|
|
||||||
}
|
|
||||||
// End of AnimeAiringStatus.php
|
|
15
src/Aviat/AnimeClient/Hummingbird/Enum/AnimeAiringStatus.php
Normal file
15
src/Aviat/AnimeClient/Hummingbird/Enum/AnimeAiringStatus.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Aviat\AnimeClient\Hummingbird\Enum;
|
||||||
|
|
||||||
|
use Aviat\Ion\Enum as BaseEnum;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Status of when anime is being/was/will be aired
|
||||||
|
*/
|
||||||
|
class AnimeAiringStatus extends BaseEnum {
|
||||||
|
const NOT_YET_AIRED = 'Not Yet Aired';
|
||||||
|
const AIRING = 'Currently Airing';
|
||||||
|
const FINISHED_AIRING = 'Finished Airing';
|
||||||
|
}
|
||||||
|
// End of AnimeAiringStatus.php
|
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Enum\Hummingbird;
|
namespace Aviat\AnimeClient\Hummingbird\Enum;
|
||||||
|
|
||||||
use Aviat\Ion\Enum;
|
use Aviat\Ion\Enum as BaseEnum;
|
||||||
|
|
||||||
class AnimeShowType extends Enum {
|
/**
|
||||||
|
* Type of Anime
|
||||||
|
*/
|
||||||
|
class AnimeShowType extends BaseEnum {
|
||||||
const TV = 'TV';
|
const TV = 'TV';
|
||||||
const MOVIE = 'Movie';
|
const MOVIE = 'Movie';
|
||||||
const OVA = 'OVA';
|
const OVA = 'OVA';
|
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Enum\Hummingbird;
|
namespace Aviat\AnimeClient\Hummingbird\Enum;
|
||||||
|
|
||||||
use Aviat\Ion\Enum;
|
use Aviat\Ion\Enum as BaseEnum;
|
||||||
|
|
||||||
class AnimeWatchingStatus extends Enum {
|
/**
|
||||||
|
* Possible values for watching status for the current anime
|
||||||
|
*/
|
||||||
|
class AnimeWatchingStatus extends BaseEnum {
|
||||||
const WATCHING = 'currently-watching';
|
const WATCHING = 'currently-watching';
|
||||||
const PLAN_TO_WATCH = 'plan-to-watch';
|
const PLAN_TO_WATCH = 'plan-to-watch';
|
||||||
const COMPLETED = 'completed';
|
const COMPLETED = 'completed';
|
@ -1,10 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Enum\Hummingbird;
|
namespace Aviat\AnimeClient\Hummingbird\Enum;
|
||||||
|
|
||||||
use Aviat\Ion\Enum;
|
use Aviat\Ion\Enum as BaseEnum;
|
||||||
|
|
||||||
class MangaReadingStatus extends Enum {
|
/**
|
||||||
|
* Possible values for current reading status of manga
|
||||||
|
*/
|
||||||
|
class MangaReadingStatus extends BaseEnum {
|
||||||
const READING = 'Currently Reading';
|
const READING = 'Currently Reading';
|
||||||
const PLAN_TO_READ = 'Plan to Read';
|
const PLAN_TO_READ = 'Plan to Read';
|
||||||
const DROPPED = 'Dropped';
|
const DROPPED = 'Dropped';
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Transformer\Hummingbird;
|
namespace Aviat\AnimeClient\Hummingbird\Transformer;
|
||||||
|
|
||||||
use Aviat\Ion\Transformer\AbstractTransformer;
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
||||||
|
|
@ -1,9 +1,12 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Transformer\Hummingbird;
|
namespace Aviat\AnimeClient\Hummingbird\Transformer;
|
||||||
|
|
||||||
use Aviat\Ion\Transformer\AbstractTransformer;
|
use Aviat\Ion\Transformer\AbstractTransformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Data transformation class for zippered Hummingbird manga
|
||||||
|
*/
|
||||||
class MangaListTransformer extends AbstractTransformer {
|
class MangaListTransformer extends AbstractTransformer {
|
||||||
|
|
||||||
/**
|
/**
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\Transformer\Hummingbird;
|
namespace Aviat\AnimeClient\Hummingbird\Transformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merges the two separate manga lists together
|
* Merges the two separate manga lists together
|
@ -6,8 +6,8 @@
|
|||||||
namespace Aviat\AnimeClient\Model;
|
namespace Aviat\AnimeClient\Model;
|
||||||
|
|
||||||
use Aviat\AnimeClient\Model\API;
|
use Aviat\AnimeClient\Model\API;
|
||||||
use Aviat\AnimeClient\Enum\Hummingbird\AnimeWatchingStatus;
|
use Aviat\AnimeClient\Hummingbird\Enum\AnimeWatchingStatus;
|
||||||
use Aviat\AnimeClient\Transformer\Hummingbird\AnimeListTransformer;
|
use Aviat\AnimeClient\Hummingbird\Transformer\AnimeListTransformer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for handling requests dealing with the anime list
|
* Model for handling requests dealing with the anime list
|
||||||
|
@ -277,6 +277,7 @@ class AnimeCollection extends DB {
|
|||||||
/**
|
/**
|
||||||
* Update genre information for selected anime
|
* Update genre information for selected anime
|
||||||
*
|
*
|
||||||
|
* @param int $anime_id The current anime
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function update_genre($anime_id)
|
private function update_genre($anime_id)
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
namespace Aviat\AnimeClient\Model;
|
namespace Aviat\AnimeClient\Model;
|
||||||
|
|
||||||
use Aviat\AnimeClient\Model\API;
|
use Aviat\AnimeClient\Model\API;
|
||||||
use Aviat\AnimeClient\Transformer\Hummingbird;
|
use Aviat\AnimeClient\Hummingbird\Transformer;
|
||||||
use Aviat\AnimeClient\Enum\Hummingbird\MangaReadingStatus;
|
use Aviat\AnimeClient\Hummingbird\Enum\MangaReadingStatus;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model for handling requests dealing with the manga list
|
* Model for handling requests dealing with the manga list
|
||||||
@ -132,7 +132,7 @@ class Manga extends API {
|
|||||||
file_put_contents($cache_file, json_encode($api_data));
|
file_put_contents($cache_file, json_encode($api_data));
|
||||||
|
|
||||||
$zippered_data = $this->zipper_lists($api_data);
|
$zippered_data = $this->zipper_lists($api_data);
|
||||||
$transformer = new Hummingbird\MangaListTransformer();
|
$transformer = new Transformer\MangaListTransformer();
|
||||||
$transformed_data = $transformer->transform_collection($zippered_data);
|
$transformed_data = $transformer->transform_collection($zippered_data);
|
||||||
file_put_contents($transformed_cache_file, json_encode($transformed_data));
|
file_put_contents($transformed_cache_file, json_encode($transformed_data));
|
||||||
return $transformed_data;
|
return $transformed_data;
|
||||||
@ -172,7 +172,7 @@ class Manga extends API {
|
|||||||
*/
|
*/
|
||||||
private function zipper_lists($raw_data)
|
private function zipper_lists($raw_data)
|
||||||
{
|
{
|
||||||
$zipper = new Hummingbird\MangaListsZipper($raw_data);
|
$zipper = new Transformer\MangaListsZipper($raw_data);
|
||||||
return $zipper->transform();
|
return $zipper->transform();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Aviat\Ion\Di;
|
namespace Aviat\Ion\Di;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for the Dependency Injection Container
|
||||||
|
*/
|
||||||
interface ContainerInterface extends \Interop\Container\ContainerInterface {
|
interface ContainerInterface extends \Interop\Container\ContainerInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,12 @@ namespace Aviat\Ion;
|
|||||||
|
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class emulating an enumeration type
|
||||||
|
*
|
||||||
|
* @method bool isValid(mixed $key)
|
||||||
|
* @method array getConstList()
|
||||||
|
*/
|
||||||
abstract class Enum {
|
abstract class Enum {
|
||||||
|
|
||||||
use StaticInstance;
|
use StaticInstance;
|
||||||
|
@ -4,6 +4,9 @@ namespace Aviat\Ion;
|
|||||||
|
|
||||||
use Aviat\Ion\Type\StringType;
|
use Aviat\Ion\Type\StringType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait to add convenience method for creating StringType objects
|
||||||
|
*/
|
||||||
trait StringWrapper {
|
trait StringWrapper {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Aviat\Ion\Transformer;
|
namespace Aviat\Ion\Transformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for data trasformation
|
||||||
|
*/
|
||||||
abstract class AbstractTransformer implements TransformerInterface {
|
abstract class AbstractTransformer implements TransformerInterface {
|
||||||
|
|
||||||
use \Aviat\Ion\StringWrapper;
|
use \Aviat\Ion\StringWrapper;
|
||||||
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
namespace Aviat\Ion\Transformer;
|
namespace Aviat\Ion\Transformer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Interface for data transformation classes
|
||||||
|
*/
|
||||||
interface TransformerInterface {
|
interface TransformerInterface {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,10 @@ namespace Aviat\Ion\Type;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wrapper class for native array methods for convenience
|
* Wrapper class for native array methods for convenience
|
||||||
|
*
|
||||||
|
* @method array chunk(int $size, bool $preserve_keys = FALSE)
|
||||||
|
* @method array pluck(mixed $column_key, mixed $index_key = NULL)
|
||||||
|
* @method array filter(callable $callback = NULL, int $flag = 0)
|
||||||
*/
|
*/
|
||||||
class ArrayType {
|
class ArrayType {
|
||||||
|
|
||||||
@ -22,7 +26,6 @@ class ArrayType {
|
|||||||
protected $native_methods = [
|
protected $native_methods = [
|
||||||
'chunk' => 'array_chunk',
|
'chunk' => 'array_chunk',
|
||||||
'pluck' => 'array_column',
|
'pluck' => 'array_column',
|
||||||
'assoc_diff' => 'array_diff_assoc',
|
|
||||||
'key_diff' => 'array_diff_key',
|
'key_diff' => 'array_diff_key',
|
||||||
'diff' => 'array_diff',
|
'diff' => 'array_diff',
|
||||||
'filter' => 'array_filter',
|
'filter' => 'array_filter',
|
||||||
@ -31,16 +34,12 @@ class ArrayType {
|
|||||||
'keys' => 'array_keys',
|
'keys' => 'array_keys',
|
||||||
'merge' => 'array_merge',
|
'merge' => 'array_merge',
|
||||||
'pad' => 'array_pad',
|
'pad' => 'array_pad',
|
||||||
'pop' => 'array_pop',
|
|
||||||
'product' => 'array_product',
|
'product' => 'array_product',
|
||||||
'push' => 'array_push',
|
|
||||||
'random' => 'array_rand',
|
'random' => 'array_rand',
|
||||||
'reduce' => 'array_reduce',
|
'reduce' => 'array_reduce',
|
||||||
'reverse' => 'array_reverse',
|
'reverse' => 'array_reverse',
|
||||||
'shift' => 'array_shift',
|
|
||||||
'sum' => 'array_sum',
|
'sum' => 'array_sum',
|
||||||
'unique' => 'array_unique',
|
'unique' => 'array_unique',
|
||||||
'unshift' => 'array_unshift',
|
|
||||||
'values' => 'array_values',
|
'values' => 'array_values',
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -51,6 +50,10 @@ class ArrayType {
|
|||||||
*/
|
*/
|
||||||
protected $native_in_place_methods = [
|
protected $native_in_place_methods = [
|
||||||
'shuffle' => 'shuffle',
|
'shuffle' => 'shuffle',
|
||||||
|
'shift' => 'array_shift',
|
||||||
|
'unshift' => 'array_unshift',
|
||||||
|
'push' => 'array_push',
|
||||||
|
'pop' => 'array_pop',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,6 +72,7 @@ class ArrayType {
|
|||||||
* @param string $method
|
* @param string $method
|
||||||
* @param array $args
|
* @param array $args
|
||||||
* @return mixed
|
* @return mixed
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __call($method, $args)
|
public function __call($method, $args)
|
||||||
{
|
{
|
||||||
@ -88,6 +92,8 @@ class ArrayType {
|
|||||||
$func($this->arr);
|
$func($this->arr);
|
||||||
return $this->arr;
|
return $this->arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
throw new \InvalidArgumentException("Method '{$method}' does not exist");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,9 @@ namespace Aviat\Ion;
|
|||||||
|
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base view response class
|
||||||
|
*/
|
||||||
abstract class View {
|
abstract class View {
|
||||||
|
|
||||||
use Di\ContainerAware;
|
use Di\ContainerAware;
|
||||||
|
@ -5,6 +5,9 @@ namespace Aviat\Ion\View;
|
|||||||
use Aviat\Ion\View\HttpView;
|
use Aviat\Ion\View\HttpView;
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View class for outputting HTML
|
||||||
|
*/
|
||||||
class HtmlView extends HttpView {
|
class HtmlView extends HttpView {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -6,6 +6,9 @@ use Aura\Web\ResponseSender;
|
|||||||
|
|
||||||
use Aviat\Ion\View as BaseView;
|
use Aviat\Ion\View as BaseView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base view class for Http output
|
||||||
|
*/
|
||||||
class HttpView extends BaseView {
|
class HttpView extends BaseView {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,9 @@ namespace Aviat\Ion\View;
|
|||||||
|
|
||||||
use Aviat\Ion\View\HttpView;
|
use Aviat\Ion\View\HttpView;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* View class to serialize Json
|
||||||
|
*/
|
||||||
class JsonView extends HttpView {
|
class JsonView extends HttpView {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Aviat\Ion\Friend;
|
use Aviat\Ion\Friend;
|
||||||
use Aviat\AnimeClient\Transformer\Hummingbird\AnimeListTransformer;
|
use Aviat\AnimeClient\Hummingbird\Transformer\AnimeListTransformer;
|
||||||
|
|
||||||
class AnimeListTransformerTest extends AnimeClient_TestCase {
|
class AnimeListTransformerTest extends AnimeClient_TestCase {
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Aviat\AnimeClient\Transformer\Hummingbird\MangaListTransformer;
|
use Aviat\AnimeClient\Hummingbird\Transformer\MangaListTransformer;
|
||||||
|
|
||||||
class MangaListTransformerTest extends AnimeClient_TestCase {
|
class MangaListTransformerTest extends AnimeClient_TestCase {
|
||||||
|
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use Aviat\AnimeClient\Transformer\Hummingbird\MangaListsZipper;
|
use Aviat\AnimeClient\Hummingbird\Transformer\MangaListsZipper;
|
||||||
|
|
||||||
class MangaListsZipperTest extends AnimeClient_TestCase {
|
class MangaListsZipperTest extends AnimeClient_TestCase {
|
||||||
|
|
@ -9,6 +9,68 @@ class ArrayTypeTest extends AnimeClient_TestCase {
|
|||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function dataCall()
|
||||||
|
{
|
||||||
|
$method_map = [
|
||||||
|
'chunk' => 'array_chunk',
|
||||||
|
'pluck' => 'array_column',
|
||||||
|
'assoc_diff' => 'array_diff_assoc',
|
||||||
|
'key_diff' => 'array_diff_key',
|
||||||
|
'diff' => 'array_diff',
|
||||||
|
'filter' => 'array_filter',
|
||||||
|
'flip' => 'array_flip',
|
||||||
|
'intersect' => 'array_intersect',
|
||||||
|
'keys' => 'array_keys',
|
||||||
|
'merge' => 'array_merge',
|
||||||
|
'pad' => 'array_pad',
|
||||||
|
'product' => 'array_product',
|
||||||
|
'random' => 'array_rand',
|
||||||
|
'reduce' => 'array_reduce',
|
||||||
|
'reverse' => 'array_reverse',
|
||||||
|
];
|
||||||
|
|
||||||
|
return [
|
||||||
|
'array_sum' => [
|
||||||
|
'method' => 'sum',
|
||||||
|
'array' => [1, 2, 3, 4, 5, 6],
|
||||||
|
'args' => [],
|
||||||
|
'expected' => 21
|
||||||
|
],
|
||||||
|
'array_unique' => [
|
||||||
|
'method' => 'unique',
|
||||||
|
'array' => [1, 1, 3, 2, 2, 2, 3, 3, 5],
|
||||||
|
'args' => [SORT_REGULAR],
|
||||||
|
'expected' => [0=>1, 2=>3, 3=>2, 8=>5]
|
||||||
|
],
|
||||||
|
'array_values' => [
|
||||||
|
'method' => 'values',
|
||||||
|
'array' => ['foo' => 'bar', 'baz' => 'foobar'],
|
||||||
|
'args' => [],
|
||||||
|
'expected' => ['bar', 'foobar']
|
||||||
|
]
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test the array methods defined for the __Call method
|
||||||
|
*
|
||||||
|
* @dataProvider dataCall
|
||||||
|
*/
|
||||||
|
public function testCall($method, $array, $args, $expected)
|
||||||
|
{
|
||||||
|
$obj = $this->arr($array);
|
||||||
|
$actual = $obj->__call($method, $args);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBadCall()
|
||||||
|
{
|
||||||
|
$obj = $this->arr([]);
|
||||||
|
|
||||||
|
$this->setExpectedException('InvalidArgumentException', "Method 'foo' does not exist");
|
||||||
|
$obj->foo();
|
||||||
|
}
|
||||||
|
|
||||||
public function testMerge()
|
public function testMerge()
|
||||||
{
|
{
|
||||||
$obj = $this->arr([1, 3, 5, 7]);
|
$obj = $this->arr([1, 3, 5, 7]);
|
||||||
@ -30,6 +92,16 @@ class ArrayTypeTest extends AnimeClient_TestCase {
|
|||||||
$this->assertTrue(is_array($actual));
|
$this->assertTrue(is_array($actual));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testHasKey()
|
||||||
|
{
|
||||||
|
$obj = $this->arr([
|
||||||
|
'a' => 'b',
|
||||||
|
'z' => 'y'
|
||||||
|
]);
|
||||||
|
$this->assertTrue($obj->has_key('a'));
|
||||||
|
$this->assertFalse($obj->has_key('b'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testHas()
|
public function testHas()
|
||||||
{
|
{
|
||||||
$obj = $this->arr([1, 2, 6, 8, 11]);
|
$obj = $this->arr([1, 2, 6, 8, 11]);
|
||||||
|
Loading…
Reference in New Issue
Block a user