changes tests

create argument helpers
start loop auto pagination
This commit is contained in:
Etienne Roudeix
2013-06-26 14:45:19 +02:00
parent 0be18e763a
commit 80380878f5
13 changed files with 352 additions and 133 deletions

View File

@@ -113,17 +113,11 @@ class ArgumentTest extends \PHPUnit_Framework_TestCase
$arguments = \PHPUnit_Framework_Assert::readAttribute($collection, 'arguments');
$collection->rewind();
while ($collection->valid()) {
$argument = $collection->current();
foreach($collection as $key => $argument) {
$this->assertEquals(
$argument,
$arguments[$collection->key()]
$arguments[$key]
);
$collection->next();
}
}
}

View File

@@ -0,0 +1,40 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type\AnyType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class AnyTypeTest extends \PHPUnit_Framework_TestCase
{
public function testAnyType()
{
$anyType = new AnyType();
$this->assertTrue($anyType->isValid(md5(rand(1000, 10000))));
}
}

View File

@@ -0,0 +1,43 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type\EnumType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class EnumTypeTest extends \PHPUnit_Framework_TestCase
{
public function testEnumType()
{
$enumType = new EnumType(array("cat", "dog"));
$this->assertTrue($enumType->isValid('cat'));
$this->assertTrue($enumType->isValid('dog'));
$this->assertFalse($enumType->isValid('monkey'));
$this->assertFalse($enumType->isValid('catdog'));
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type\FloatType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class FloatTypeTest extends \PHPUnit_Framework_TestCase
{
public function testFloatType()
{
$floatType = new FloatType();
$this->assertTrue($floatType->isValid('1.1'));
$this->assertTrue($floatType->isValid(2.2));
$this->assertFalse($floatType->isValid('foo'));
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type\IntListType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class IntListTypeTest extends \PHPUnit_Framework_TestCase
{
public function testIntListType()
{
$intListType = new IntListType();
$this->assertTrue($intListType->isValid('1'));
$this->assertTrue($intListType->isValid('1,2,3'));
$this->assertFalse($intListType->isValid('1,2,3.3'));
}
}

View File

@@ -0,0 +1,42 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type\IntType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class IntTypeTest extends \PHPUnit_Framework_TestCase
{
public function testIntType()
{
$intType = new IntType();
$this->assertTrue($intType->isValid('1'));
$this->assertTrue($intType->isValid(2));
$this->assertFalse($intType->isValid('3.3'));
}
}

View File

@@ -0,0 +1,41 @@
<?php
/*************************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/*************************************************************************************/
namespace Thelia\Tests\Type;
use Thelia\Type\JsonType;
/**
*
* @author Etienne Roudeix <eroudeix@openstudio.fr>
*
*/
class JsonTypeTest extends \PHPUnit_Framework_TestCase
{
public function testJsonType()
{
$jsonType = new JsonType();
$this->assertTrue($jsonType->isValid('{"k0":"v0","k1":"v1","k2":"v2"}'));
$this->assertFalse($jsonType->isValid('1,2,3'));
}
}

View File

@@ -37,18 +37,18 @@ class TypeTest extends \PHPUnit_Framework_TestCase
{
$collection = new TypeCollection(
new Type\AnyType(),
new Type\AnyType()
new Type\IntType()
);
$collection->addType(
new Type\AnyType()
new Type\FloatType()
);
$this->assertAttributeEquals(
array(
new Type\AnyType(),
new Type\AnyType(),
new Type\AnyType(),
new Type\IntType(),
new Type\FloatType(),
),
'types',
$collection
@@ -59,55 +59,18 @@ class TypeTest extends \PHPUnit_Framework_TestCase
{
$collection = new TypeCollection(
new Type\AnyType(),
new Type\AnyType(),
new Type\AnyType()
new Type\IntType(),
new Type\FloatType()
);
$types = \PHPUnit_Framework_Assert::readAttribute($collection, 'types');
$collection->rewind();
while ($collection->valid()) {
$type = $collection->current();
foreach($collection as $key => $type) {
$this->assertEquals(
$type,
$types[$collection->key()]
$types[$key]
);
$collection->next();
}
}
public function testTypes()
{
$anyType = new Type\AnyType();
$this->assertTrue($anyType->isValid(md5(rand(1000, 10000))));
$intType = new Type\IntType();
$this->assertTrue($intType->isValid('1'));
$this->assertTrue($intType->isValid(2));
$this->assertFalse($intType->isValid('3.3'));
$floatType = new Type\FloatType();
$this->assertTrue($floatType->isValid('1.1'));
$this->assertTrue($floatType->isValid(2.2));
$this->assertFalse($floatType->isValid('foo'));
$enumType = new Type\EnumType(array("cat", "dog"));
$this->assertTrue($enumType->isValid('cat'));
$this->assertTrue($enumType->isValid('dog'));
$this->assertFalse($enumType->isValid('monkey'));
$this->assertFalse($enumType->isValid('catdog'));
$intListType = new Type\IntListType();
$this->assertTrue($intListType->isValid('1'));
$this->assertTrue($intListType->isValid('1,2,3'));
$this->assertFalse($intListType->isValid('1,2,3.3'));
$jsonType = new Type\JsonType();
$this->assertTrue($jsonType->isValid('{"k0":"v0","k1":"v1","k2":"v2"}'));
$this->assertFalse($jsonType->isValid('1,2,3'));
}
}