First commit
This commit is contained in:
commit
2c39931e93
|
@ -0,0 +1,3 @@
|
||||||
|
.idea/
|
||||||
|
vendor/
|
||||||
|
*~
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$header = <<<EOF
|
||||||
|
This file is part of ArrayObjectArray.
|
||||||
|
|
||||||
|
(copyleft) R. Eric Wheeler <sikofitt@gmail.com>
|
||||||
|
|
||||||
|
For the full copyright and license information, please view the LICENSE
|
||||||
|
file that was distributed with this source code.
|
||||||
|
EOF;
|
||||||
|
|
||||||
|
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header);
|
||||||
|
|
||||||
|
$finder = Symfony\CS\Finder\DefaultFinder::create()
|
||||||
|
->exclude('vendor')
|
||||||
|
->ignoreDotFiles(true)
|
||||||
|
->ignoreVCS(true)
|
||||||
|
->name('*.php')
|
||||||
|
->in(__DIR__ . '/src')
|
||||||
|
;
|
||||||
|
|
||||||
|
return Symfony\CS\Config\Config::create()
|
||||||
|
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
|
||||||
|
->fixers(
|
||||||
|
[
|
||||||
|
'symfony',
|
||||||
|
'header_comment',
|
||||||
|
'ordered_use',
|
||||||
|
'php_unit_construct',
|
||||||
|
'php_unit_strict',
|
||||||
|
'strict',
|
||||||
|
'strict_param',
|
||||||
|
'symfony',
|
||||||
|
'newline_after_open_tag',
|
||||||
|
'phpdoc_order',
|
||||||
|
'long_array_syntax',
|
||||||
|
'short_echo_tag',
|
||||||
|
'-multiple_use',
|
||||||
|
'spaces'
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->finder($finder)
|
||||||
|
;
|
|
@ -0,0 +1,21 @@
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2016 R. Eric Wheeler <sikofitt@gmail.com>
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
|
@ -0,0 +1,30 @@
|
||||||
|
{
|
||||||
|
"name": "sikofitt/array-object-array",
|
||||||
|
"description": "ArrayObject class that implements array functions through __call",
|
||||||
|
"type": "library",
|
||||||
|
"require": {
|
||||||
|
"php": ">=5.3"
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^5.4",
|
||||||
|
"friendsofphp/php-cs-fixer": "^1.11"
|
||||||
|
},
|
||||||
|
"license": "MIT",
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "sikofitt",
|
||||||
|
"email": "sikofitt@gmail.com"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"autoload": {
|
||||||
|
"psr-4": {
|
||||||
|
"Sikofitt\\Utility\\": "src/Sikofitt/Utility/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"Sikofitt\\Tests\\": "tests/Sikofitt/Tests/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"minimum-stability": "stable"
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,27 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<phpunit backupGlobals="false"
|
||||||
|
backupStaticAttributes="false"
|
||||||
|
beStrictAboutTestsThatDoNotTestAnything="true"
|
||||||
|
colors="true"
|
||||||
|
convertErrorsToExceptions="true"
|
||||||
|
convertNoticesToExceptions="true"
|
||||||
|
convertWarningsToExceptions="true"
|
||||||
|
processIsolation="false"
|
||||||
|
stopOnFailure="false"
|
||||||
|
syntaxCheck="false"
|
||||||
|
bootstrap="vendor/autoload.php"
|
||||||
|
verbose="true"
|
||||||
|
debug="true"
|
||||||
|
>
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="ArrayObjectArray tests">
|
||||||
|
<directory>./tests/Sikofitt</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
<filter>
|
||||||
|
<whitelist>
|
||||||
|
<directory>./src</directory>
|
||||||
|
</whitelist>
|
||||||
|
</filter>
|
||||||
|
</phpunit>
|
|
@ -0,0 +1,41 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of ArrayObjectArray.
|
||||||
|
*
|
||||||
|
* (copyleft) R. Eric Wheeler <sikofitt@gmail.com>
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sikofitt\Utility;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ArrayObjectArray
|
||||||
|
*
|
||||||
|
* Adds array functions to the ArrayObject class.
|
||||||
|
* https://secure.php.net/manual/en/class.arrayobject.php#107079
|
||||||
|
*
|
||||||
|
* @package Sikofitt\Utility
|
||||||
|
*/
|
||||||
|
class ArrayObjectArray extends \ArrayObject
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @param $function
|
||||||
|
* @param $argv
|
||||||
|
*
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
public function __call($function, $argv)
|
||||||
|
{
|
||||||
|
if (!is_callable($function) || substr($function, 0, 6) !== 'array_') {
|
||||||
|
throw new \BadMethodCallException(__CLASS__ . '->' . $function);
|
||||||
|
}
|
||||||
|
|
||||||
|
return call_user_func_array(
|
||||||
|
$function,
|
||||||
|
array_merge(array($this->getArrayCopy()), $argv)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,71 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* This file is part of ArrayObjectArray.
|
||||||
|
*
|
||||||
|
* @file ArrayObjectArrayTest.php
|
||||||
|
*
|
||||||
|
* R. Eric Wheeler <reric@ee.stanford.edu>
|
||||||
|
*
|
||||||
|
* 7/19/16 / 1:58 PM
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Sikofitt\Tests;
|
||||||
|
|
||||||
|
|
||||||
|
use Sikofitt\Utility\ArrayObjectArray;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ArrayObjectArrayTest
|
||||||
|
*
|
||||||
|
* @package Sikofitt\Tests
|
||||||
|
*/
|
||||||
|
class ArrayObjectArrayTest extends \PHPUnit_Framework_TestCase {
|
||||||
|
|
||||||
|
private $arrayObjectArray;
|
||||||
|
private $workingArray;
|
||||||
|
|
||||||
|
public function setUp() {
|
||||||
|
$this->workingArray = array(
|
||||||
|
'this' => 'that',
|
||||||
|
'that' => 'this',
|
||||||
|
'what' => 'who',
|
||||||
|
'check' => 'out',
|
||||||
|
);
|
||||||
|
$this->arrayObjectArray = new ArrayObjectArray($this->workingArray);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @coversDefaultClass
|
||||||
|
*/
|
||||||
|
public function testArrayObjectArrayInstance() {
|
||||||
|
$this->assertInstanceOf(ArrayObjectArray::class, $this->arrayObjectArray);
|
||||||
|
$this->assertInstanceOf(\ArrayObject::class, $this->arrayObjectArray);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArrayKeys()
|
||||||
|
{
|
||||||
|
$this->assertEquals(array_keys($this->workingArray), $this->arrayObjectArray->array_keys());
|
||||||
|
$this->assertEquals(array_values($this->workingArray), $this->arrayObjectArray->array_values());
|
||||||
|
|
||||||
|
$this->assertEquals($this->workingArray, $this->arrayObjectArray->getArrayCopy());
|
||||||
|
$this->assertCount(4, $this->arrayObjectArray);
|
||||||
|
|
||||||
|
$this->arrayObjectArray->offsetUnset('this');
|
||||||
|
$this->assertCount(3, $this->arrayObjectArray);
|
||||||
|
|
||||||
|
$this->arrayObjectArray->append(['this' => 'that']);
|
||||||
|
$this->assertCount(4, $this->arrayObjectArray);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* @expectedException \BadMethodCallException
|
||||||
|
*/
|
||||||
|
public function testException()
|
||||||
|
{
|
||||||
|
$this->arrayObjectArray->error();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue