[Argil-svn] SF.net SVN: argil: [523] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
From: <tsw...@us...> - 2007-05-24 01:50:39
|
Revision: 523
http://argil.svn.sourceforge.net/argil/?rev=523&view=rev
Author: tswicegood
Date: 2007-05-23 18:50:40 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Add in test to fix issue with annotations that have no parameters and
refactor loading of specs so everything can be loaded.
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Property.php
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/src/Argil/Reflection/Property.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Property.php 2007-05-24 01:39:14 UTC (rev 522)
+++ branches/experimental/src/Argil/Reflection/Property.php 2007-05-24 01:50:40 UTC (rev 523)
@@ -1,5 +1,5 @@
<?php
-require_once 'Argil/Specification/Length.php';
+
class Argil_Reflection_Property
{
private $_decorated = null;
@@ -14,15 +14,21 @@
$method
) , $arguments);
}
+
+ /**
+ * @todo refactor out specification loading into Argil_Loader_Specification
+ */
public function isValid($object)
{
$doc = $this->getDocComment();
$name = $this->getName();
$value = $object->$name;
- if (preg_match_all('/@(is|isNot) ([a-z]+) (.*)/', $doc, $matches)) {
+ if (preg_match_all('/@(is|isNot) ([a-z]+) ?(.*)/i', $doc, $matches)) {
foreach($matches[2] as $key => $spec) {
$spec = ucfirst($spec);
- $reflection = new ReflectionClass('Argil_Specification_' . $spec);
+ $specName = 'Argil_Specification_' . $spec;
+ require_once str_replace('_', '/', $specName) . '.php';
+ $reflection = new ReflectionClass($specName);
$args = array_merge(array(
$value
) , explode(' ', $matches[3][$key]));
@@ -42,6 +48,7 @@
}
}
}
+
return true;
}
}
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-05-24 01:39:14 UTC (rev 522)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-05-24 01:50:40 UTC (rev 523)
@@ -14,6 +14,11 @@
* @isNot length 5 <
*/
public $notLessThanFive;
+
+ /**
+ * @is String
+ */
+ public $string = '';
}
class Argil_Reflection_PropertyTest extends UnitTestCase
{
@@ -53,4 +58,18 @@
$object->notLessThanFive = '12345';
$this->assertTrue($attribute->isValid($object));
}
+
+ public function testAllowsSpecsWithoutParameters()
+ {
+ $object = new ArgilSamplePropertyObjectForReflection();
+ $reflection = new ReflectionObject($object);
+
+ $properties = $reflection->getProperties();
+ $stringReflection = new Argil_Reflection_Property($properties[4]);
+
+ $this->assertEqual('string', $stringReflection->getName(), 'sanity check');
+ $object->string = 123;
+ $this->assertFalse($stringReflection->isValid($object));
+
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|