This repository has been archived by the owner on Oct 18, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
more tests, more stringproperty functions, test extensions of objecta…
…rray and arraylist
- Loading branch information
1 parent
3a34f2b
commit cbeccc8
Showing
4 changed files
with
208 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,49 @@ | ||
<?php | ||
|
||
use PerrysLambda\Converter\ListConverter; | ||
use PerrysLambda\ArrayList; | ||
use PerrysLambda\ObjectArray; | ||
use PerrysLambda\Serializer\Serializer; | ||
use PerrysLambda\IArrayable; | ||
use PerrysLambda\ArrayBase; | ||
use PerrysLambda\Converter\ItemConverter; | ||
use PerrysLambda\IItemConverter; | ||
use PerrysLambda\Serializer\DateTimeSerializer; | ||
use PerrysLambda\Serializer\BooleanSerializer; | ||
|
||
class CustomTypeTest extends PHPUnit_Framework_TestCase | ||
{ | ||
|
||
public function testCustomTypes() | ||
{ | ||
$this->assertSame(true, true); | ||
$data = array( | ||
array('name' => 'anemone', 'ranking'=>5), | ||
array('name' => 'steak', 'ranking'=>10), | ||
array('name' => 'crocus', 'ranking'=>5.5), | ||
array('name' => 'super mario', 'ranking'=>8), | ||
array('name' => 'daisy', 'ranking'=>6), | ||
array('name' => 'money', 'ranking'=>7), | ||
); | ||
|
||
$list = MyArrayList::asType('MyObjectArray', $data); | ||
$this->assertSame(true, $list->first() instanceof MyObjectArray); | ||
|
||
$flowers = $list->getFlowers(); | ||
$this->assertSame(true, $flowers instanceof MyArrayList); | ||
$this->assertSame(3, $flowers->length()); | ||
$this->assertSame('daisy', $flowers->last()->name); | ||
$this->assertSame(true, $flowers->last()->isFlower()); | ||
} | ||
|
||
} | ||
|
||
class MyArrayList extends ArrayList | ||
{ | ||
public function getFlowers() | ||
{ | ||
return $this->where(function($v) { return $v->isFlower(); }); | ||
} | ||
} | ||
|
||
class MyObjectArray extends ObjectArray | ||
{ | ||
|
||
public function isFlower() | ||
{ | ||
//return in_array($this->getScalar('flower')->, array('')); | ||
$flowers = new ArrayList(array('anemone', 'crocus', 'daisy', 'hibiscus')); | ||
return $flowers->any(function($v) { return $v==$this->nameScalar->toLower()->toString(); }); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters