argil-svn Mailing List for Argil Framework
Status: Alpha
Brought to you by:
tswicegood
You can subscribe to this list here.
| 2007 |
Jan
|
Feb
(18) |
Mar
(8) |
Apr
(11) |
May
(23) |
Jun
(1) |
Jul
(6) |
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
|---|
|
From: <tsw...@us...> - 2007-07-15 01:07:37
|
Revision: 548
http://argil.svn.sourceforge.net/argil/?rev=548&view=rev
Author: tswicegood
Date: 2007-07-14 18:07:39 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Remove annotation code from Argil - now uses Domain51_Tool_Annotation
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/AllTest.php
branches/experimental/tests/config.php
Removed Paths:
-------------
branches/experimental/src/Argil/Util/Annotation/
branches/experimental/tests/Argil/Util/Annotation/
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-07-14 22:31:57 UTC (rev 547)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-07-15 01:07:39 UTC (rev 548)
@@ -1,7 +1,7 @@
<?php
require_once 'Argil/Reflection/Property.php';
require_once 'Argil/Reflection/PropertyList.php';
-require_once 'Argil/Util/Annotation/Parser.php';
+require_once 'Domain51/Tool/Annotation/Parser.php';
class Argil_Reflection_Object
{
@@ -29,7 +29,7 @@
public function getTable()
{
- $parser = new Argil_Util_Annotation_Parser();
+ $parser = new Domain51_Tool_Annotation_Parser();
$collection = $parser->parse($this->_decorated->getDocComment());
if (!$collection->has('table')) {
@@ -41,7 +41,7 @@
public function getPrimaryKey()
{
- $parser = new Argil_Util_Annotation_Parser();
+ $parser = new Domain51_Tool_Annotation_Parser();
$collection = $parser->parse($this->_decorated->getDocComment());
if (!$collection->has('primaryKey')) {
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-07-14 22:31:57 UTC (rev 547)
+++ branches/experimental/tests/AllTest.php 2007-07-15 01:07:39 UTC (rev 548)
@@ -13,9 +13,6 @@
$this->addTestFile('Argil/RouteTest.php');
$this->addTestFile('Argil/Specification/LengthTest.php');
$this->addTestFile('Argil/Specification/StringTest.php');
- $this->addTestFile('Argil/Util/Annotation/CollectionTest.php');
- $this->addTestFile('Argil/Util/Annotation/ParserTest.php');
- $this->addTestFile('Argil/Util/Annotation/ValueTest.php');
$this->addTestFile('Argil/Util/System/DirectoryTest.php');
$this->addTestFile('Argil/Util/System/FileTest.php');
$this->addTestFile('Argil/Util/Template/CamelCapsToUnderscoreTest.php');
Modified: branches/experimental/tests/config.php
===================================================================
--- branches/experimental/tests/config.php 2007-07-14 22:31:57 UTC (rev 547)
+++ branches/experimental/tests/config.php 2007-07-15 01:07:39 UTC (rev 548)
@@ -2,7 +2,9 @@
require_once 'simpletest/unit_tester.php';
require_once 'simpletest/mock_objects.php';
require_once 'simpletest/autorun.php';
-set_include_path(dirname(__FILE__) . PATH_SEPARATOR . dirname(__FILE__) . '/../src' . PATH_SEPARATOR . get_include_path());
+set_include_path(
+ dirname(__FILE__) . PATH_SEPARATOR .
+ dirname(__FILE__) . '/../src' . PATH_SEPARATOR .
+ get_include_path()
+);
-require_once 'Argil/Util/Annotation/Value.php';
-Mock::generate('Argil_Util_Annotation_Value');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-07-14 22:31:54
|
Revision: 547
http://argil.svn.sourceforge.net/argil/?rev=547&view=rev
Author: tswicegood
Date: 2007-07-14 15:31:57 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Add in rudimentary support for all tests
Modified Paths:
--------------
branches/experimental/tests/AllTest.php
Added Paths:
-----------
branches/experimental/src/Argil/Controller/
branches/experimental/src/Argil/Controller/Loader.php
branches/experimental/src/Argil/Controller/Locator.php
branches/experimental/tests/Argil/Controller/
branches/experimental/tests/Argil/Controller/LoaderTest.php
branches/experimental/tests/Argil/Controller/LocatorTest.php
branches/experimental/tests/support/controllers/
branches/experimental/tests/support/controllers/PersonController.php
Added: branches/experimental/src/Argil/Controller/Loader.php
===================================================================
--- branches/experimental/src/Argil/Controller/Loader.php (rev 0)
+++ branches/experimental/src/Argil/Controller/Loader.php 2007-07-14 22:31:57 UTC (rev 547)
@@ -0,0 +1,26 @@
+<?php
+
+require_once 'Argil/Controller/Locator.php';
+require_once 'Argil/Util/System/Directory.php';
+
+class Argil_Controller_Loader
+{
+ private $_locator = null;
+
+ public function __construct(Argil_Util_System_Directory $directory)
+ {
+ $this->_locator = new Argil_Controller_Locator($directory);
+ }
+
+ public function load($name)
+ {
+ $controller_name = $name . 'Controller';
+ if (!class_exists($controller_name)) {
+ $file = $this->_locator->locate($name);
+ $file->requireOnce();
+ }
+
+ $controller = new $controller_name();
+ return $controller;
+ }
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Controller/Locator.php
===================================================================
--- branches/experimental/src/Argil/Controller/Locator.php (rev 0)
+++ branches/experimental/src/Argil/Controller/Locator.php 2007-07-14 22:31:57 UTC (rev 547)
@@ -0,0 +1,21 @@
+<?php
+
+require_once 'Argil/Util/System/Directory.php';
+require_once 'Argil/Util/System/File.php';
+
+class Argil_Controller_Locator
+{
+ private $_path = null;
+
+ public function __construct(Argil_Util_System_Directory $path)
+ {
+ $this->_path = $path;
+ }
+
+ public function locate($name)
+ {
+ $expected_path = (string)$this->_path . '/' . $name . 'Controller.php';
+ $file = new Argil_Util_System_File($expected_path);
+ return $file;
+ }
+}
\ No newline at end of file
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-07-14 22:12:03 UTC (rev 546)
+++ branches/experimental/tests/AllTest.php 2007-07-14 22:31:57 UTC (rev 547)
@@ -4,6 +4,8 @@
{
public function __construct()
{
+ $this->addTestFile('Argil/Controller/LoaderTest.php');
+ $this->addTestFile('Argil/Controller/LocatorTest.php');
$this->addTestFile('Argil/Model/ContainerTest.php');
$this->addTestFile('Argil/Reflection/ObjectTest.php');
$this->addTestFile('Argil/Reflection/PropertyListTest.php');
Added: branches/experimental/tests/Argil/Controller/LoaderTest.php
===================================================================
--- branches/experimental/tests/Argil/Controller/LoaderTest.php (rev 0)
+++ branches/experimental/tests/Argil/Controller/LoaderTest.php 2007-07-14 22:31:57 UTC (rev 547)
@@ -0,0 +1,20 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Controller/Loader.php';
+
+class Argil_Controller_LoaderTest extends UnitTestCase
+{
+ public function testLoadsAndReturnsANewController()
+ {
+ $directory = new Argil_Util_System_Directory(
+ dirname(__FILE__) . '/../../support/controllers'
+ );
+
+ $loader = new Argil_Controller_Loader($directory);
+ $controller = $loader->load('Person');
+
+ $this->assertIsA($controller, 'PersonController');
+
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Controller/LocatorTest.php
===================================================================
--- branches/experimental/tests/Argil/Controller/LocatorTest.php (rev 0)
+++ branches/experimental/tests/Argil/Controller/LocatorTest.php 2007-07-14 22:31:57 UTC (rev 547)
@@ -0,0 +1,26 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Controller/Locator.php';
+
+class Argil_Controller_LocatorTest extends UnitTestCase
+{
+ public function testRequiresADirectoryObjectAtConstruct()
+ {
+ $reflection = new ReflectionClass('Argil_Controller_Locator');
+ $constructor = $reflection->getConstructor();
+ $firstParam = array_shift($constructor->getParameters());
+ $this->assertFalse($firstParam->isOptional());
+ $this->assertEqual('Argil_Util_System_Directory', $firstParam->getClass()->getName());
+ }
+
+ public function testLocateReturnsAValidFileForInclusion()
+ {
+ $directory = new Argil_Util_System_Directory(dirname(__FILE__) . '/../../support/controllers');
+ $locator = new Argil_Controller_Locator($directory);
+ $file = $locator->locate('Person');
+ $this->assertIsA($file, 'Argil_Util_System_File');
+ $this->assertEqual('PersonController.php', $file->file_name);
+ $this->assertEqual($directory, $file->directory);
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/support/controllers/PersonController.php
===================================================================
--- branches/experimental/tests/support/controllers/PersonController.php (rev 0)
+++ branches/experimental/tests/support/controllers/PersonController.php 2007-07-14 22:31:57 UTC (rev 547)
@@ -0,0 +1,9 @@
+<?php
+
+class PersonController
+{
+ public function __construct()
+ {
+
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-07-14 22:12:02
|
Revision: 546
http://argil.svn.sourceforge.net/argil/?rev=546&view=rev
Author: tswicegood
Date: 2007-07-14 15:12:03 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Remove test that's not in the repo yet - error in previous commit
Modified Paths:
--------------
branches/experimental/tests/AllTest.php
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-07-14 22:10:56 UTC (rev 545)
+++ branches/experimental/tests/AllTest.php 2007-07-14 22:12:03 UTC (rev 546)
@@ -4,7 +4,6 @@
{
public function __construct()
{
- $this->addTestFile('Argil/Controller/LocatorTest.php');
$this->addTestFile('Argil/Model/ContainerTest.php');
$this->addTestFile('Argil/Reflection/ObjectTest.php');
$this->addTestFile('Argil/Reflection/PropertyListTest.php');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-07-14 22:10:54
|
Revision: 545
http://argil.svn.sourceforge.net/argil/?rev=545&view=rev
Author: tswicegood
Date: 2007-07-14 15:10:56 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Add in support directory
Modified Paths:
--------------
branches/experimental/tests/AllTest.php
Added Paths:
-----------
branches/experimental/tests/support/
branches/experimental/tests/support/HelloWorld.php
branches/experimental/tests/support/RandomNumber.php
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-07-14 22:09:35 UTC (rev 544)
+++ branches/experimental/tests/AllTest.php 2007-07-14 22:10:56 UTC (rev 545)
@@ -4,6 +4,7 @@
{
public function __construct()
{
+ $this->addTestFile('Argil/Controller/LocatorTest.php');
$this->addTestFile('Argil/Model/ContainerTest.php');
$this->addTestFile('Argil/Reflection/ObjectTest.php');
$this->addTestFile('Argil/Reflection/PropertyListTest.php');
Added: branches/experimental/tests/support/HelloWorld.php
===================================================================
--- branches/experimental/tests/support/HelloWorld.php (rev 0)
+++ branches/experimental/tests/support/HelloWorld.php 2007-07-14 22:10:56 UTC (rev 545)
@@ -0,0 +1,3 @@
+<?php
+
+echo "Hello World";
Added: branches/experimental/tests/support/RandomNumber.php
===================================================================
--- branches/experimental/tests/support/RandomNumber.php (rev 0)
+++ branches/experimental/tests/support/RandomNumber.php 2007-07-14 22:10:56 UTC (rev 545)
@@ -0,0 +1,3 @@
+<?php
+
+echo "Random Number: " . rand(100, 200);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-07-14 22:09:33
|
Revision: 544
http://argil.svn.sourceforge.net/argil/?rev=544&view=rev
Author: tswicegood
Date: 2007-07-14 15:09:35 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Add in Argil_Util_System_File code
Modified Paths:
--------------
branches/experimental/tests/AllTest.php
Added Paths:
-----------
branches/experimental/src/Argil/Util/System/File/
branches/experimental/src/Argil/Util/System/File/Exception.php
branches/experimental/src/Argil/Util/System/File.php
branches/experimental/tests/Argil/Util/System/FileTest.php
Added: branches/experimental/src/Argil/Util/System/File/Exception.php
===================================================================
--- branches/experimental/src/Argil/Util/System/File/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Util/System/File/Exception.php 2007-07-14 22:09:35 UTC (rev 544)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_System_File_Exception extends Exception
+{
+
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Util/System/File.php
===================================================================
--- branches/experimental/src/Argil/Util/System/File.php (rev 0)
+++ branches/experimental/src/Argil/Util/System/File.php 2007-07-14 22:09:35 UTC (rev 544)
@@ -0,0 +1,45 @@
+<?php
+
+require_once 'Argil/Util/System/Directory.php';
+require_once 'Argil/Util/System/File/Exception.php';
+
+class Argil_Util_System_File
+{
+ private $_file_path = null;
+
+ public function __construct($file_path)
+ {
+ if (!is_file($file_path)) {
+ throw new Argil_Util_System_File_Exception('invalid file provided');
+ }
+
+ $this->_file_path = $file_path;
+ }
+
+ public function __get($key)
+ {
+ switch ($key) {
+ case 'file_name' :
+ return basename($this->_file_path);
+ case 'directory' :
+ return new Argil_Util_System_Directory(dirname($this->_file_path));
+ }
+ }
+
+ public function __set($key, $value)
+ {
+ throw new Argil_Util_System_File_Exception(
+ 'attempted to set read-only file_name property'
+ );
+ }
+
+ public function requireOnce()
+ {
+ require_once $this->_file_path;
+ }
+
+ public function inc()
+ {
+ include $this->_file_path;
+ }
+}
\ No newline at end of file
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-07-14 22:05:46 UTC (rev 543)
+++ branches/experimental/tests/AllTest.php 2007-07-14 22:09:35 UTC (rev 544)
@@ -14,6 +14,8 @@
$this->addTestFile('Argil/Util/Annotation/CollectionTest.php');
$this->addTestFile('Argil/Util/Annotation/ParserTest.php');
$this->addTestFile('Argil/Util/Annotation/ValueTest.php');
+ $this->addTestFile('Argil/Util/System/DirectoryTest.php');
+ $this->addTestFile('Argil/Util/System/FileTest.php');
$this->addTestFile('Argil/Util/Template/CamelCapsToUnderscoreTest.php');
}
}
Added: branches/experimental/tests/Argil/Util/System/FileTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/System/FileTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/System/FileTest.php 2007-07-14 22:09:35 UTC (rev 544)
@@ -0,0 +1,80 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/System/File.php';
+
+class Argil_Util_System_FileTest extends UnitTestCase
+{
+ public function testThrowsAnExceptionOnInvalidFile()
+ {
+ try {
+ new Argil_Util_System_File(dirname(__FILE__) . '/unknown');
+ $this->fail('exception not caught');
+ } catch (Argil_Util_System_File_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual(
+ 'invalid file provided',
+ $e->getMessage()
+ );
+ }
+
+ new Argil_Util_System_File(__FILE__);
+ $this->pass('properly instantiated');
+ }
+
+ public function testHasReadOnlyPropertyFile_name()
+ {
+ $file = new Argil_Util_System_File(__FILE__);
+ $this->assertEqual(basename(__FILE__), $file->file_name);
+
+ try {
+ $file->file_name = 'new value';
+ $this->fail('exception not caught');
+ } catch (Argil_Util_System_File_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual(
+ 'attempted to set read-only file_name property',
+ $e->getMessage()
+ );
+ }
+ }
+
+ public function testHasReadOnlyDirectoryProperty()
+ {
+ $file = new Argil_Util_System_File(__FILE__);
+ $dir = $file->directory;
+ $this->assertIsA($dir, 'Argil_Util_System_Directory');
+ $this->assertEqual((string)$dir, dirname(__FILE__));
+ }
+
+ public function testRequireOnceLoadsFileOnce()
+ {
+ $file = new Argil_Util_System_File(dirname(__FILE__) . '/../../../support/HelloWorld.php');
+ ob_start();
+ $file->requireOnce();
+ $buf = ob_get_clean();
+
+ $this->assertEqual('Hello World', $buf);
+ unset($buf);
+
+ ob_start();
+ $file->requireOnce();
+ $buf = ob_get_clean();
+ $this->assertEqual('', $buf, "Should be an empty string now that it's been included once");
+ }
+
+ public function testIncAllowsFileToBeLoadedMultipleTimes()
+ {
+ $pattern = '/^Random Number: [12][0-9]{2}/';
+ $file = new Argil_Util_System_File(dirname(__FILE__) . '/../../../support/RandomNumber.php');
+ ob_start();
+ $file->inc();
+ $buffer_one = ob_get_clean();
+ ob_start();
+ $file->inc();
+ $buffer_two = ob_get_clean();
+
+ $this->assertWantedPattern($pattern, $buffer_one);
+ $this->assertWantedPAttern($pattern, $buffer_two);
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-07-14 22:05:50
|
Revision: 543
http://argil.svn.sourceforge.net/argil/?rev=543&view=rev
Author: tswicegood
Date: 2007-07-14 15:05:46 -0700 (Sat, 14 Jul 2007)
Log Message:
-----------
Remove Argil_Pdo - should have already been committed
Removed Paths:
-------------
branches/experimental/src/Argil/Pdo.php
branches/experimental/tests/Argil/PdoTest.php
Deleted: branches/experimental/src/Argil/Pdo.php
===================================================================
--- branches/experimental/src/Argil/Pdo.php 2007-06-01 23:54:06 UTC (rev 542)
+++ branches/experimental/src/Argil/Pdo.php 2007-07-14 22:05:46 UTC (rev 543)
@@ -1,36 +0,0 @@
-<?php
-
-class Argil_Pdo
-{
- public function __construct() { }
-
- public function __sleep() { }
-
- public function __wakeup() { }
-
- public function beginTransaction() { }
-
- public function commit() { }
-
- public function errorCode() { }
-
- public function errorInfo() { }
-
- public function exec($statement) { }
-
- public function getAttribute($attribute) { }
-
- public function getAvailableDrivers() { }
-
- public function lastInsertId($name = null) { }
-
- public function prepare($string, array $driver_options = array()) { }
-
- public function query($statement, $p2 = null, $p3 = null, array $p4 = null) { }
-
- public function quote($string, $parameter_type = PDO::PARAM_STR) { }
-
- public function rollBack() { }
-
- public function setAttribute($attribute, $value) { }
-}
\ No newline at end of file
Deleted: branches/experimental/tests/Argil/PdoTest.php
===================================================================
--- branches/experimental/tests/Argil/PdoTest.php 2007-06-01 23:54:06 UTC (rev 542)
+++ branches/experimental/tests/Argil/PdoTest.php 2007-07-14 22:05:46 UTC (rev 543)
@@ -1,25 +0,0 @@
-<?php
-
-require_once dirname(__FILE__) . '/../config.php';
-require_once 'Argil/Pdo.php';
-
-class Argil_PdoTest extends UnitTestCase
-{
- public function testHasAllOfTheSameMethodsAsPdo()
- {
- $argil = new ReflectionClass('Argil_Pdo');
- $pdo = new ReflectionClass('PDO');
-
- $argilMethods = array();
- foreach ($argil->getMethods() as $argilMethod) {
- $argilMethods[] = $argilMethod->getName();
- }
-
- foreach ($pdo->getMethods() as $pdoMethod) {
- $this->assertTrue(
- in_array($pdoMethod->getName(), $argilMethods),
- "Checking that {$pdoMethod->getName()} is declared"
- );
- }
- }
-}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-06-01 23:54:06
|
Revision: 542
http://argil.svn.sourceforge.net/argil/?rev=542&view=rev
Author: tswicegood
Date: 2007-06-01 16:54:06 -0700 (Fri, 01 Jun 2007)
Log Message:
-----------
Add Argil_Util_System_Directory and appropriate tests
Added Paths:
-----------
branches/experimental/src/Argil/Util/System/
branches/experimental/src/Argil/Util/System/Directory/
branches/experimental/src/Argil/Util/System/Directory/Exception.php
branches/experimental/src/Argil/Util/System/Directory.php
branches/experimental/tests/Argil/Util/System/
branches/experimental/tests/Argil/Util/System/DirectoryTest.php
Added: branches/experimental/src/Argil/Util/System/Directory/Exception.php
===================================================================
--- branches/experimental/src/Argil/Util/System/Directory/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Util/System/Directory/Exception.php 2007-06-01 23:54:06 UTC (rev 542)
@@ -0,0 +1,3 @@
+<?php
+
+class Argil_Util_System_Directory_Exception extends Exception { }
\ No newline at end of file
Added: branches/experimental/src/Argil/Util/System/Directory.php
===================================================================
--- branches/experimental/src/Argil/Util/System/Directory.php (rev 0)
+++ branches/experimental/src/Argil/Util/System/Directory.php 2007-06-01 23:54:06 UTC (rev 542)
@@ -0,0 +1,39 @@
+<?php
+
+require_once 'Argil/Util/System/Directory/Exception.php';
+
+class Argil_Util_System_Directory
+{
+ private $_path = null;
+
+ public function __construct($path)
+ {
+ if (!is_dir($path)) {
+ throw new Argil_Util_System_Directory_Exception('invalid path provided');
+ }
+
+ $this->_path = $path;
+ }
+
+ public function __get($key)
+ {
+ switch ($key) {
+ case 'path':
+ return $this->_path;
+ case 'real_path' :
+ return realpath($this->_path);
+ }
+ }
+
+ public function __set($key, $value)
+ {
+ throw new Argil_Util_System_Directory_Exception(
+ "attempting to set read-only {$key} property"
+ );
+ }
+
+ public function __toString()
+ {
+ return $this->_path;
+ }
+}
Added: branches/experimental/tests/Argil/Util/System/DirectoryTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/System/DirectoryTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/System/DirectoryTest.php 2007-06-01 23:54:06 UTC (rev 542)
@@ -0,0 +1,76 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/System/Directory.php';
+
+class Argil_Util_System_DirectoryTest extends UnitTestCase
+{
+ public function testThrowsAnExceptionWhenProvidedWithInvalidDirectory()
+ {
+ try {
+ new Argil_Util_System_Directory(__FILE__);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_System_Directory_Exception $e) {
+ $this->pass('Exception caught');
+ $this->assertEqual(
+ 'invalid path provided',
+ $e->getMessage()
+ );
+ }
+
+ new Argil_Util_System_Directory(dirname(__FILE__));
+ $this->pass('properly instantiated');
+ }
+
+ public function testHasReadOnlyPathProperty()
+ {
+ $path = new Argil_Util_System_Directory(dirname(__FILE__));
+ $this->assertEqual(dirname(__FILE__), $path->path);
+ unset($path);
+
+ $path = new Argil_Util_System_Directory(dirname(__FILE__) . '/..');
+ $this->assertEqual(dirname(__FILE__) . '/..', $path->path);
+
+ try {
+ $path->path = 'new value';
+ $this->fail('exception not caught');
+ } catch (Argil_Util_System_Directory_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual(
+ 'attempting to set read-only path property',
+ $e->getMessage()
+ );
+ }
+ }
+
+ public function testWhenCastToStringPathObjectEqualsPathProperty()
+ {
+ $path = new Argil_Util_System_Directory(dirname(__FILE__));
+ $this->assertEqual(dirname(__FILE__), (string)$path);
+ unset($path);
+
+ $path = new Argil_Util_System_Directory(dirname(__FILE__) . '/..');
+ $this->assertEqual(dirname(__FILE__) . '/..', (string)$path);
+ }
+
+ public function testHasReadOnlyRealpathProperty()
+ {
+ $path = new Argil_Util_System_Directory(dirname(__FILE__) . '/..');
+ $this->assertEqual(realpath(dirname(__FILE__) . '/..'), $path->real_path);
+ unset($path);
+
+ $path = new Argil_Util_System_Directory(dirname(__FILE__));
+ $this->assertEqual(dirname(__FILE__), $path->real_path);
+
+ try {
+ $path->real_path = 'new value';
+ $this->fail('exception not caught');
+ } catch (Argil_Util_System_Directory_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual(
+ 'attempting to set read-only real_path property',
+ $e->getMessage()
+ );
+ }
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-31 00:00:32
|
Revision: 541
http://argil.svn.sourceforge.net/argil/?rev=541&view=rev
Author: tswicegood
Date: 2007-05-30 17:00:32 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Add the first pass at a generic Model Locator
Added Paths:
-----------
branches/experimental/src/Argil/Model/Locator.php
branches/experimental/tests/Argil/Model/LocatorTest.php
Added: branches/experimental/src/Argil/Model/Locator.php
===================================================================
--- branches/experimental/src/Argil/Model/Locator.php (rev 0)
+++ branches/experimental/src/Argil/Model/Locator.php 2007-05-31 00:00:32 UTC (rev 541)
@@ -0,0 +1,47 @@
+<?php
+
+require_once 'Argil/Model/Container.php';
+require_once 'Argil/Util/Template/CamelCapsToUnderscore.php';
+class Argil_Model_Locator
+{
+ private $_pdo = null;
+
+ public function __construct(PDO $pdo)
+ {
+ $this->_pdo = $pdo;
+ }
+
+ public function __call($method, $arguments)
+ {
+ if (preg_match('/^findBy(.+)$/', $method, $matches)) {
+ $property = new Argil_Util_Template_CamelCapsToUnderscore($matches[1]);
+ $value = array_shift($arguments);
+ $model = array_shift($arguments);
+ return $this->_findByGivenProperty((string)$property, $value, $model);
+ }
+ }
+
+ public function findById($id, $model)
+ {
+ $meta = new Argil_Model_Container($model);
+ return $this->_findByGivenProperty($meta->getPrimaryKey(), $id, $model);
+ }
+
+ private function _findByGivenProperty($property, $value, $model)
+ {
+ $meta = new Argil_Model_Container($model);
+ $statement = $this->_pdo->prepare(
+ "SELECT * FROM {$meta->getTable()} WHERE {$property} = :value"
+ );
+
+ $statement->execute(array(
+ ':value' => $value
+ ));
+
+ $data = $statement->fetch(PDO::FETCH_ASSOC);
+ foreach ($data as $key => $value) {
+ $model->$key = $value;
+ }
+ return new Argil_Model_Container($model);
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Model/LocatorTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/LocatorTest.php (rev 0)
+++ branches/experimental/tests/Argil/Model/LocatorTest.php 2007-05-31 00:00:32 UTC (rev 541)
@@ -0,0 +1,101 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../config.php';
+require_once 'Argil/Model/Locator.php';
+
+/**
+ * @table person
+ */
+class SimpleArgilPerson
+{
+
+}
+
+class Argil_Model_LocatorTest extends UnitTestCase
+{
+ private $_pdo = null;
+ private $_random = '';
+ public function setup()
+ {
+ $pdo = new PDO('sqlite::memory:');
+ $this->assertTrue(
+ $pdo->exec('CREATE TABLE person (
+ person_id INT,
+ first_name VARCHAR(50),
+ last_name VARCHAR(100)
+ )'
+ ) !== false,
+ 'sanity check - make sure the table is setup properly'
+ );
+
+ $this->assertTrue(
+ $pdo->exec(
+ "INSERT INTO person VALUES ('1', 'Travis', 'Swicegood')"
+ ) !== false,
+ 'sanity check - make sure the rows are inserted'
+ );
+
+ $this->_random = 'Random, ' . rand(1, 10);
+ $this->assertTrue(
+ $pdo->exec(
+ "INSERT INTO person VALUES ('2', 'Joe', '" . $this->_random . "')"
+ ) !== false,
+ 'sanity check - make sure the rows are inserted'
+ );
+ $this->_pdo = $pdo;
+ }
+
+ public function testUsedToLocateModelsInPersistentStorageAndReturnThemInModelContainers()
+ {
+
+ }
+
+ public function testRequiresPdoObjectAsFirstParameterAtInstantiation()
+ {
+ $reflection = new ReflectionClass('Argil_Model_Locator');
+ $param = array_shift($reflection->getConstructor()->getParameters());
+ $this->assertFalse($param->isOptional());
+ $this->assertEqual($param->getClass()->getName(), 'PDO');
+ }
+
+ public function testCanLocateAGivenModel()
+ {
+ $locator = new Argil_Model_Locator($this->_pdo);
+ $model = $locator->findById(1, new SimpleArgilPerson());
+ $this->assertIsA($model, 'Argil_Model_Container');
+ $this->assertTrue($model->is('SimpleArgilPerson'));
+ $this->assertEqual('Travis', $model->first_name);
+ $this->assertEqual('Swicegood', $model->last_name);
+ unset($model);
+
+ $model = $locator->findById(2, new SimpleArgilPerson());
+ $this->assertIsA($model, 'Argil_Model_Container');
+ $this->assertTrue($model->is('SimpleArgilPerson'));
+ $this->assertEqual('Joe', $model->first_name);
+ $this->assertEqual($this->_random, $model->last_name);
+ }
+
+ public function testCanUseFindByPropertyNameMethodToFindAnObject()
+ {
+ $locator = new Argil_Model_Locator($this->_pdo);
+ $model = $locator->findByFirstName('Travis', new SimpleArgilPerson());
+ $this->assertIsA($model, 'Argil_Model_Container');
+ $this->assertTrue($model->is('SimpleArgilPerson'));
+ $this->assertEqual('Travis', $model->first_name);
+ $this->assertEqual('Swicegood', $model->last_name);
+ unset($model);
+
+ $model = $locator->findByLastName('Swicegood', new SimpleArgilPerson());
+ $this->assertIsA($model, 'Argil_Model_Container');
+ $this->assertTrue($model->is('SimpleArgilPerson'));
+ $this->assertEqual('Travis', $model->first_name);
+ $this->assertEqual('Swicegood', $model->last_name);
+ unset($model);
+
+ $model = $locator->findByLastName($this->_random, new SimpleArgilPerson());
+ $this->assertIsA($model, 'Argil_Model_Container');
+ $this->assertTrue($model->is('SimpleArgilPerson'));
+ $this->assertEqual('Joe', $model->first_name);
+ $this->assertEqual($this->_random, $model->last_name);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-30 22:41:30
|
Revision: 540
http://argil.svn.sourceforge.net/argil/?rev=540&view=rev
Author: tswicegood
Date: 2007-05-30 15:41:32 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Add in getPrimaryKey() to use when locating an object in persistent storage
Modified Paths:
--------------
branches/experimental/src/Argil/Model/Container.php
branches/experimental/tests/Argil/Model/ContainerTest.php
Modified: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php 2007-05-30 21:11:16 UTC (rev 539)
+++ branches/experimental/src/Argil/Model/Container.php 2007-05-30 22:41:32 UTC (rev 540)
@@ -58,4 +58,16 @@
return (string)new Argil_Util_Template_CamelCapsToUnderscore($reflection->getName());
}
+
+ public function getPrimaryKey()
+ {
+ reset($this->_contained);
+ $reflection = new Argil_Reflection_Object(current($this->_contained));
+ $primary_key = $reflection->getPrimaryKey();
+ if (!empty($primary_key)) {
+ return $primary_key;
+ }
+
+ return $this->getTable() . '_id';
+ }
}
Modified: branches/experimental/tests/Argil/Model/ContainerTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-30 21:11:16 UTC (rev 539)
+++ branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-30 22:41:32 UTC (rev 540)
@@ -24,6 +24,13 @@
{
}
+/**
+ * @primaryKey id
+ */
+class ArgilModelWithId
+{
+}
+
class Argil_Model_ContainerTest extends UnitTestCase
{
public function testWillTellWhatTypeOfObjectThisContains()
@@ -98,4 +105,20 @@
$container = new Argil_Model_Container(new ArgilModelWithTable());
$this->assertEqual($container->getTable(), 'some_table');
}
+
+ public function testCanDeterminePrimaryKeyBasedOnTableNamePlusUnderscoreId()
+ {
+ $container = new Argil_Model_Container(new ArgilSampleModel());
+ $this->assertEqual($container->getPrimaryKey(), 'argil_sample_model_id');
+ unset($container);
+
+ $container = new Argil_Model_Container(new ArgilModelWithTable());
+ $this->assertEqual($container->getPrimaryKey(), 'some_table_id');
+ }
+
+ public function testUsesModelPrimaryAnnotationIfSet()
+ {
+ $container = new Argil_Model_Container(new ArgilModelWithId());
+ $this->assertEqual($container->getPrimaryKey(), 'id');
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-30 21:11:14
|
Revision: 539
http://argil.svn.sourceforge.net/argil/?rev=539&view=rev
Author: tswicegood
Date: 2007-05-30 14:11:16 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Adds the ability for @primaryKey to allow multi-column keys
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-30 20:58:12 UTC (rev 538)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-30 21:11:16 UTC (rev 539)
@@ -48,6 +48,7 @@
return '';
}
- return array_shift($collection->filter('primaryKey')->current()->params);
+ $keys = $collection->filter('primaryKey')->current()->params;
+ return ((count($keys) == 1) ? array_shift($keys) : $keys);
}
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-30 20:58:12 UTC (rev 538)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-30 21:11:16 UTC (rev 539)
@@ -18,6 +18,11 @@
*/
class ArgilSampleReflectionObjectWithPrimaryKey { }
+/**
+ * @primaryKey col1 col2
+ */
+class ArgilSampleReflectionObjectWithCompoundPrimaryKey { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -63,4 +68,12 @@
$reflection = new Argil_Reflection_Object($this);
$this->assertEqual('', $reflection->getPrimaryKey());
}
+
+ public function testReturnsAnArrayForMultiColumnPrimaryKeys()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithCompoundPrimaryKey()
+ );
+ $this->assertEqual(array('col1', 'col2'), $reflection->getPrimaryKey());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-30 20:58:11
|
Revision: 538
http://argil.svn.sourceforge.net/argil/?rev=538&view=rev
Author: tswicegood
Date: 2007-05-30 13:58:12 -0700 (Wed, 30 May 2007)
Log Message:
-----------
Add a getPrimaryKey() method
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-29 19:59:35 UTC (rev 537)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-30 20:58:12 UTC (rev 538)
@@ -38,4 +38,16 @@
return array_shift($collection->filter('table')->current()->params);
}
+
+ public function getPrimaryKey()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $collection = $parser->parse($this->_decorated->getDocComment());
+
+ if (!$collection->has('primaryKey')) {
+ return '';
+ }
+
+ return array_shift($collection->filter('primaryKey')->current()->params);
+ }
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-29 19:59:35 UTC (rev 537)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-30 20:58:12 UTC (rev 538)
@@ -13,6 +13,11 @@
*/
class ArgilSampleReflectionObjectWithTable { }
+/**
+ * @primaryKey a_custom_id
+ */
+class ArgilSampleReflectionObjectWithPrimaryKey { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -44,4 +49,18 @@
$reflection = new Argil_Reflection_Object($this);
$this->assertEqual('', $reflection->getTable());
}
+
+ public function testReturnsPrimaryKeyIfPrimaryKeyAnnotationSet()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithPrimaryKey()
+ );
+ $this->assertEqual('a_custom_id', $reflection->getPrimaryKey());
+ }
+
+ public function testReturnsEmptyStringIfPrimaryAnnotationIsNotSet()
+ {
+ $reflection = new Argil_Reflection_Object($this);
+ $this->assertEqual('', $reflection->getPrimaryKey());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-29 19:59:38
|
Revision: 537
http://argil.svn.sourceforge.net/argil/?rev=537&view=rev
Author: tswicegood
Date: 2007-05-29 12:59:35 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Add in a stub for Argil_Pdo
Added Paths:
-----------
branches/experimental/src/Argil/Pdo.php
branches/experimental/tests/Argil/PdoTest.php
Added: branches/experimental/src/Argil/Pdo.php
===================================================================
--- branches/experimental/src/Argil/Pdo.php (rev 0)
+++ branches/experimental/src/Argil/Pdo.php 2007-05-29 19:59:35 UTC (rev 537)
@@ -0,0 +1,36 @@
+<?php
+
+class Argil_Pdo
+{
+ public function __construct() { }
+
+ public function __sleep() { }
+
+ public function __wakeup() { }
+
+ public function beginTransaction() { }
+
+ public function commit() { }
+
+ public function errorCode() { }
+
+ public function errorInfo() { }
+
+ public function exec($statement) { }
+
+ public function getAttribute($attribute) { }
+
+ public function getAvailableDrivers() { }
+
+ public function lastInsertId($name = null) { }
+
+ public function prepare($string, array $driver_options = array()) { }
+
+ public function query($statement, $p2 = null, $p3 = null, array $p4 = null) { }
+
+ public function quote($string, $parameter_type = PDO::PARAM_STR) { }
+
+ public function rollBack() { }
+
+ public function setAttribute($attribute, $value) { }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/PdoTest.php
===================================================================
--- branches/experimental/tests/Argil/PdoTest.php (rev 0)
+++ branches/experimental/tests/Argil/PdoTest.php 2007-05-29 19:59:35 UTC (rev 537)
@@ -0,0 +1,25 @@
+<?php
+
+require_once dirname(__FILE__) . '/../config.php';
+require_once 'Argil/Pdo.php';
+
+class Argil_PdoTest extends UnitTestCase
+{
+ public function testHasAllOfTheSameMethodsAsPdo()
+ {
+ $argil = new ReflectionClass('Argil_Pdo');
+ $pdo = new ReflectionClass('PDO');
+
+ $argilMethods = array();
+ foreach ($argil->getMethods() as $argilMethod) {
+ $argilMethods[] = $argilMethod->getName();
+ }
+
+ foreach ($pdo->getMethods() as $pdoMethod) {
+ $this->assertTrue(
+ in_array($pdoMethod->getName(), $argilMethods),
+ "Checking that {$pdoMethod->getName()} is declared"
+ );
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-29 18:10:53
|
Revision: 536
http://argil.svn.sourceforge.net/argil/?rev=536&view=rev
Author: tswicegood
Date: 2007-05-29 11:10:46 -0700 (Tue, 29 May 2007)
Log Message:
-----------
Add in Argil_Config and the appropriate tests
Added Paths:
-----------
branches/experimental/src/Argil/Config/
branches/experimental/src/Argil/Config/Exception.php
branches/experimental/src/Argil/Config.php
branches/experimental/tests/Argil/ConfigTest.php
Added: branches/experimental/src/Argil/Config/Exception.php
===================================================================
--- branches/experimental/src/Argil/Config/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Config/Exception.php 2007-05-29 18:10:46 UTC (rev 536)
@@ -0,0 +1,3 @@
+<?php
+
+class Argil_Config_Exception extends Exception { }
\ No newline at end of file
Added: branches/experimental/src/Argil/Config.php
===================================================================
--- branches/experimental/src/Argil/Config.php (rev 0)
+++ branches/experimental/src/Argil/Config.php 2007-05-29 18:10:46 UTC (rev 536)
@@ -0,0 +1,30 @@
+<?php
+
+require_once 'Argil/Config/Exception.php';
+
+class Argil_Config
+{
+ private $_stack = array();
+
+ public function __construct(array $values = array())
+ {
+ $this->_stack = $values;
+ }
+
+ public function __get($key)
+ {
+ return $this->_stack[$key];
+ }
+
+ public function __set($key, $value)
+ {
+ throw new Argil_Config_Exception(
+ 'attempted to set read-only property [' . $key . ']'
+ );
+ }
+
+ public function __isset($key)
+ {
+ return isset($this->_stack[$key]);
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/ConfigTest.php
===================================================================
--- branches/experimental/tests/Argil/ConfigTest.php (rev 0)
+++ branches/experimental/tests/Argil/ConfigTest.php 2007-05-29 18:10:46 UTC (rev 536)
@@ -0,0 +1,58 @@
+<?php
+
+require_once dirname(__FILE__) . '/../config.php';
+require_once 'Argil/Config.php';
+
+class Argil_ConfigTest extends UnitTestCase
+{
+ public function testTakesAnOptionalArrayAtConstruct()
+ {
+ new Argil_Config(array());
+ $this->assertNoErrors();
+
+ new Argil_config();
+ $this->assertNoErrors();
+
+ $reflection = new ReflectionObject(new Argil_Config(array()));
+ $param = array_shift($reflection->getConstructor()->getParameters());
+ $this->assertTrue($param->isArray());
+ $this->assertTrue($param->isOptional());
+ }
+
+ public function testArrayKeysAreAccessibleViaObjectProperty()
+ {
+ $array = array(
+ 'string' => 'hello world',
+ 'int' => 123,
+ 'random' => rand(10, 20),
+ );
+
+ $config = new Argil_Config($array);
+ foreach ($array as $key => $value) {
+ $this->assertTrue(isset($config->$key));
+ // mutate the key and make sure it still doesn't work
+ $badKey = $key . '_mutated';
+ $this->assertFalse(isset($config->$badKey));
+
+ $this->assertEqual($config->$key, $value);
+ }
+ }
+
+ public function testPropertiesAreReadOnly()
+ {
+ $key = 'random_' . rand(10, 20);
+ $random = rand(10, 20);
+ $config = new Argil_Config(array($key => $random));
+ $this->assertEqual($config->$key, $random, 'sanity check');
+ try {
+ $config->$key = 'new value';
+ $this->fail('exception not thrown');
+ } catch (Argil_Config_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual(
+ $e->getMessage(),
+ 'attempted to set read-only property [' . $key . ']'
+ );
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:43:12
|
Revision: 535
http://argil.svn.sourceforge.net/argil/?rev=535&view=rev
Author: tswicegood
Date: 2007-05-25 16:43:02 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in all of the new tests to the test suite
Modified Paths:
--------------
branches/experimental/tests/AllTest.php
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-05-25 23:42:04 UTC (rev 534)
+++ branches/experimental/tests/AllTest.php 2007-05-25 23:43:02 UTC (rev 535)
@@ -11,5 +11,9 @@
$this->addTestFile('Argil/RouteTest.php');
$this->addTestFile('Argil/Specification/LengthTest.php');
$this->addTestFile('Argil/Specification/StringTest.php');
+ $this->addTestFile('Argil/Util/Annotation/CollectionTest.php');
+ $this->addTestFile('Argil/Util/Annotation/ParserTest.php');
+ $this->addTestFile('Argil/Util/Annotation/ValueTest.php');
+ $this->addTestFile('Argil/Util/Template/CamelCapsToUnderscoreTest.php');
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:42:24
|
Revision: 534
http://argil.svn.sourceforge.net/argil/?rev=534&view=rev
Author: tswicegood
Date: 2007-05-25 16:42:04 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Make sure there's a Mock Argil_Util_Annotation_Value object available
Modified Paths:
--------------
branches/experimental/tests/config.php
Modified: branches/experimental/tests/config.php
===================================================================
--- branches/experimental/tests/config.php 2007-05-25 23:40:24 UTC (rev 533)
+++ branches/experimental/tests/config.php 2007-05-25 23:42:04 UTC (rev 534)
@@ -3,3 +3,6 @@
require_once 'simpletest/mock_objects.php';
require_once 'simpletest/autorun.php';
set_include_path(dirname(__FILE__) . PATH_SEPARATOR . dirname(__FILE__) . '/../src' . PATH_SEPARATOR . get_include_path());
+
+require_once 'Argil/Util/Annotation/Value.php';
+Mock::generate('Argil_Util_Annotation_Value');
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:41:45
|
Revision: 533
http://argil.svn.sourceforge.net/argil/?rev=533&view=rev
Author: tswicegood
Date: 2007-05-25 16:40:24 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add getTable() to the Container
Modified Paths:
--------------
branches/experimental/src/Argil/Model/Container.php
branches/experimental/tests/Argil/Model/ContainerTest.php
Modified: branches/experimental/src/Argil/Model/Container.php
===================================================================
--- branches/experimental/src/Argil/Model/Container.php 2007-05-25 23:35:50 UTC (rev 532)
+++ branches/experimental/src/Argil/Model/Container.php 2007-05-25 23:40:24 UTC (rev 533)
@@ -1,5 +1,7 @@
<?php
require_once 'Argil/Reflection/Object.php';
+require_once 'Argil/Util/Template/CamelCapsToUnderscore.php';
+
class Argil_Model_Container
{
private $_contained = array();
@@ -44,4 +46,16 @@
}
}
}
+
+ public function getTable()
+ {
+ reset($this->_contained);
+ $reflection = new Argil_Reflection_Object(current($this->_contained));
+ $table = $reflection->getTable();
+ if (!empty($table)) {
+ return $table;
+ }
+
+ return (string)new Argil_Util_Template_CamelCapsToUnderscore($reflection->getName());
+ }
}
Modified: branches/experimental/tests/Argil/Model/ContainerTest.php
===================================================================
--- branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-25 23:35:50 UTC (rev 532)
+++ branches/experimental/tests/Argil/Model/ContainerTest.php 2007-05-25 23:40:24 UTC (rev 533)
@@ -1,6 +1,7 @@
<?php
require_once dirname(__FILE__) . '/../../config.php';
require_once 'Argil/Model/Container.php';
+
class ArgilSampleModel
{
/**
@@ -15,6 +16,14 @@
class ArgilSampleModelTwo
{
}
+
+/**
+ * @table some_table
+ */
+class ArgilModelWithTable
+{
+}
+
class Argil_Model_ContainerTest extends UnitTestCase
{
public function testWillTellWhatTypeOfObjectThisContains()
@@ -73,4 +82,20 @@
}
$this->assertEqual($container->lengthOfTen, '1234567890');
}
+
+ public function testCanDetermineTableName()
+ {
+ $container = new Argil_Model_Container(new ArgilSampleModel());
+ $this->assertEqual($container->getTable(), 'argil_sample_model');
+ unset($container);
+
+ $container = new Argil_Model_Container(new ArgilSampleModelTwo());
+ $this->assertEqual($container->getTable(), 'argil_sample_model_two');
+ }
+
+ public function testUsesModelTablePropertyIfSet()
+ {
+ $container = new Argil_Model_Container(new ArgilModelWithTable());
+ $this->assertEqual($container->getTable(), 'some_table');
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:35:49
|
Revision: 532
http://argil.svn.sourceforge.net/argil/?rev=532&view=rev
Author: tswicegood
Date: 2007-05-25 16:35:50 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in a camel caps to underscore converter
Added Paths:
-----------
branches/experimental/src/Argil/Util/Template/
branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/
branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php
branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php
branches/experimental/tests/Argil/Util/Template/
branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php
Added: branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php
===================================================================
--- branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore/Exception.php 2007-05-25 23:35:50 UTC (rev 532)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_Template_CamelCapsToUnderscore_Exception extends Exception
+{
+
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php
===================================================================
--- branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php (rev 0)
+++ branches/experimental/src/Argil/Util/Template/CamelCapsToUnderscore.php 2007-05-25 23:35:50 UTC (rev 532)
@@ -0,0 +1,21 @@
+<?php
+
+require_once 'Argil/Util/Template/CamelCapsToUnderscore/Exception.php';
+
+class Argil_Util_Template_CamelCapsToUnderscore
+{
+ private $value = 'camel_caps';
+
+ public function __construct($string)
+ {
+ if (!is_string($string) || empty($string)) {
+ throw new Argil_Util_Template_CamelCapsToUnderscore_Exception();
+ }
+ $this->value = strtolower(preg_replace('/(.)([A-Z])/', '$1_$2', $string));
+ }
+
+ public function __toString()
+ {
+ return $this->value;
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Template/CamelCapsToUnderscoreTest.php 2007-05-25 23:35:50 UTC (rev 532)
@@ -0,0 +1,58 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Template/CamelCapsToUnderscore.php';
+
+class Argil_Util_Template_CamelCapsToUnderscoreTest extends UnitTestCase
+{
+ public function testConvertsCamelCapsToUnderscoredStrings()
+ {
+ $template = new Argil_Util_Template_CamelCapsToUnderscore('CamelCaps');
+ $this->assertEqual((string)$template, 'camel_caps');
+ unset($template);
+
+ $template = new Argil_Util_Template_CamelCapsToUnderscore('CamelCapsButLonger');
+ $this->assertEqual((string)$template, 'camel_caps_but_longer');
+ }
+
+ public function testRequiresANonEmptyStringAsOnlyParameterInConstruct()
+ {
+ new Argil_Util_Template_CamelCapsToUnderscore('non-empty');
+ $this->pass('exception not thrown');
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore('');
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore(1);
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore(array());
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore(123.321);
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+
+ try {
+ new Argil_Util_Template_CamelCapsToUnderscore($this);
+ $this->fail('exception not caught');
+ } catch(Argil_Util_Template_CamelCapsToUnderscore_Exception $e) {
+ $this->pass('exception caught');
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:07:47
|
Revision: 531
http://argil.svn.sourceforge.net/argil/?rev=531&view=rev
Author: tswicegood
Date: 2007-05-25 16:07:49 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add getTable() to the reflection object
Modified Paths:
--------------
branches/experimental/src/Argil/Reflection/Object.php
branches/experimental/tests/Argil/Reflection/ObjectTest.php
Modified: branches/experimental/src/Argil/Reflection/Object.php
===================================================================
--- branches/experimental/src/Argil/Reflection/Object.php 2007-05-25 23:00:37 UTC (rev 530)
+++ branches/experimental/src/Argil/Reflection/Object.php 2007-05-25 23:07:49 UTC (rev 531)
@@ -1,6 +1,8 @@
<?php
require_once 'Argil/Reflection/Property.php';
require_once 'Argil/Reflection/PropertyList.php';
+require_once 'Argil/Util/Annotation/Parser.php';
+
class Argil_Reflection_Object
{
private $_decorated = null;
@@ -24,4 +26,16 @@
{
return new Argil_Reflection_Property($this->_decorated->getProperty($name));
}
+
+ public function getTable()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $collection = $parser->parse($this->_decorated->getDocComment());
+
+ if (!$collection->has('table')) {
+ return '';
+ }
+
+ return array_shift($collection->filter('table')->current()->params);
+ }
}
Modified: branches/experimental/tests/Argil/Reflection/ObjectTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-25 23:00:37 UTC (rev 530)
+++ branches/experimental/tests/Argil/Reflection/ObjectTest.php 2007-05-25 23:07:49 UTC (rev 531)
@@ -7,6 +7,12 @@
protected $protectedProperty = '';
private $privateProperty = '';
}
+
+/**
+ * @table a_custom_table
+ */
+class ArgilSampleReflectionObjectWithTable { }
+
class Argil_Reflection_ObjectTest extends UnitTestCase
{
public function testReturnsArrayOfProperties()
@@ -23,4 +29,19 @@
$property = $reflection->getProperty('publicProperty');
$this->assertIsA($property, 'Argil_Reflection_Property');
}
+
+ public function testReturnsTableNameIfTableAnnotationSet()
+ {
+ $reflection = new Argil_Reflection_Object(
+ new ArgilSampleReflectionObjectWithTable()
+ );
+
+ $this->assertEqual('a_custom_table', $reflection->getTable());
+ }
+
+ public function testReturnsEmptyStringIfTableAnnotationIsNotSet()
+ {
+ $reflection = new Argil_Reflection_Object($this);
+ $this->assertEqual('', $reflection->getTable());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:00:37
|
Revision: 530
http://argil.svn.sourceforge.net/argil/?rev=530&view=rev
Author: tswicegood
Date: 2007-05-25 16:00:37 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in the Annotation_Parser object and appropriate tests
Added Paths:
-----------
branches/experimental/src/Argil/Util/Annotation/Parser.php
branches/experimental/tests/Argil/Util/Annotation/ParserTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Parser.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Parser.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Parser.php 2007-05-25 23:00:37 UTC (rev 530)
@@ -0,0 +1,21 @@
+<?php
+
+require_once 'Argil/Util/Annotation/Collection.php';
+
+class Argil_Util_Annotation_Parser
+{
+ public function parse($string)
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ if (!preg_match_all('/@([a-z]+) ?(.*)/i', $string, $matches)) {
+ return $collection;
+ }
+
+ foreach ($matches[1] as $key => $match) {
+ $params = !empty($matches[2][$key]) ? explode(' ', $matches[2][$key]) : array();
+
+ $collection->add(new Argil_Util_Annotation_Value($match, $params));
+ }
+ return $collection;
+ }
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/ParserTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ParserTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/ParserTest.php 2007-05-25 23:00:37 UTC (rev 530)
@@ -0,0 +1,54 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Parser.php';
+
+class Argil_Util_Annontation_ParserTest extends UnitTestCase
+{
+ public function testReturnsACollectionOfAnnotationsAfterParsing()
+ {
+ $parser = new Argil_Util_Annotation_Parser();
+ $list = $parser->parse('');
+
+ $this->assertIsA($list, 'Argil_Util_Annotation_Collection');
+ $this->assertEqual(0, $list->count());
+ unset($list);
+
+ $random = rand(10, 20);
+ $str = <<<END
+/**
+ * @is String
+ * @dummy
+ * @table string_table
+ * @isNot Length {$random} <
+ */
+END;
+ $list = $parser->parse($str);
+ $this->assertEqual(4, $list->count());
+
+ $this->assertTrue($list->has('is'));
+ $this->assertTrue($list->has('dummy'));
+ $this->assertTrue($list->has('table'));
+ $this->assertTrue($list->has('isNot'));
+
+ $is = $list->filter('is')->current();
+ $this->assertIsA($is, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($is->name, 'is');
+ $this->assertEqual($is->params, array('String'));
+
+ $dummy = $list->filter('dummy')->current();
+ $this->assertIsA($dummy, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($dummy->name, 'dummy');
+ $this->assertEqual($dummy->params, array());
+
+ $table = $list->filter('table')->current();
+ $this->assertIsA($table, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($table->name, 'table');
+ $this->assertEqual($table->params, array('string_table'));
+
+ $isNot = $list->filter('isNot')->current();
+ $this->assertIsA($isNot, 'Argil_Util_Annotation_Value');
+ $this->assertEqual($isNot->name, 'isNot');
+ $this->assertEqual($isNot->params, array('Length', $random, '<'));
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 23:00:06
|
Revision: 529
http://argil.svn.sourceforge.net/argil/?rev=529&view=rev
Author: tswicegood
Date: 2007-05-25 16:00:08 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in the fleshing out of the Annotation_Collection object
Modified Paths:
--------------
branches/experimental/src/Argil/Util/Annotation/Collection.php
branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
Modified: branches/experimental/src/Argil/Util/Annotation/Collection.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Collection.php 2007-05-25 18:51:33 UTC (rev 528)
+++ branches/experimental/src/Argil/Util/Annotation/Collection.php 2007-05-25 23:00:08 UTC (rev 529)
@@ -1,10 +1,11 @@
<?php
-class Argil_Util_Annotation_Collection
+class Argil_Util_Annotation_Collection implements Iterator
{
+ private $_cursor = 0;
private $_stack = array();
- public function add(Argil_Util_Annotation_Value $annontation)
+ public function add(Argil_Util_Annotation_Value $annotation)
{
$this->_stack[] = $annotation;
}
@@ -13,4 +14,70 @@
{
return count($this->_stack);
}
+
+ public function has($name)
+ {
+ $stackCount = $this->count();
+ for ($i = 0; $i < $stackCount; $i++) {
+ if ($this->_stack[$i]->name == $name) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public function filter($names)
+ {
+ $names = (array)$names;
+
+ $return = new self();
+ $stackCount = $this->count();
+ for ($i = 0; $i < $stackCount; $i++) {
+ if (in_array($this->_stack[$i]->name, $names)) {
+ $return->add($this->_stack[$i]);
+ }
+ }
+
+ return $return;
+ }
+
+ public function filterOut($names)
+ {
+ $names = (array)$names;
+
+ $return = new self();
+ $stackCount = $this->count();
+ for ($i = 0; $i < $stackCount; $i++) {
+ if (!in_array($this->_stack[$i]->name, $names)) {
+ $return->add($this->_stack[$i]);
+ }
+ }
+
+ return $return;
+ }
+
+ public function current()
+ {
+ return $this->_stack[$this->_cursor];
+ }
+
+ public function key()
+ {
+ return $this->valid() ? $this->_cursor : null;
+ }
+
+ public function next()
+ {
+ $this->_cursor++;
+ }
+
+ public function rewind()
+ {
+ $this->_cursor = 0;
+ }
+
+ public function valid()
+ {
+ return $this->_cursor < $this->count();
+ }
}
\ No newline at end of file
Modified: branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php 2007-05-25 18:51:33 UTC (rev 528)
+++ branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php 2007-05-25 23:00:08 UTC (rev 529)
@@ -12,4 +12,117 @@
$collection->add(new MockArgil_Util_Annotation_Value());
$this->assertEqual(1, $collection->count());
}
+
+ public function testHasTellsWhetherTheCollectionContainsASpecificAnnotation()
+ {
+ $annotation = new MockArgil_Util_Annotation_Value();
+ $annotation->setReturnValue('__get', 'known', array('name'));
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($annotation);
+
+ $this->assertTrue($collection->has('known'));
+ $this->assertFalse($collection->has('unknown'));
+ }
+
+ public function testCanReturnANewCollectionWithFilteredResults()
+ {
+ $is = new Argil_Util_Annotation_Value('is');
+ $isNot = new Argil_Util_Annotation_Value('isNot');
+
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($is);
+ $collection->add($isNot);
+
+ $this->assertEqual(2, $collection->count(), 'sanity check');
+ $this->assertTrue($collection->has('is'), 'sanity check');
+ $this->assertTrue($collection->has('isNot'), 'sanity check');
+
+ $isCollection = $collection->filter('is');
+ $this->assertEqual(1, $isCollection->count());
+ $this->assertTrue($isCollection->has('is'));
+ $this->assertFalse($isCollection->has('isNot'));
+
+ $isNotCollection = $collection->filter('isNot');
+ $this->assertEqual(1, $isNotCollection->count());
+ $this->assertFalse($isNotCollection->has('is'));
+ $this->assertTrue($isNotCollection->has('isNot'));
+ }
+
+ public function testCanReturnANewCollectionWithMultipleFilteredResults()
+ {
+ $is = new Argil_Util_Annotation_Value('is');
+ $isNot = new Argil_Util_Annotation_Value('isNot');
+
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($is);
+ $collection->add($isNot);
+
+ $this->assertEqual(2, $collection->count(), 'sanity check');
+ $this->assertTrue($collection->has('is'), 'sanity check');
+ $this->assertTrue($collection->has('isNot'), 'sanity check');
+
+ $newCollection = $collection->filter(array('is', 'isNot'));
+ $this->assertEqual(2, $newCollection->count());
+ $this->assertTrue($newCollection->has('is'));
+ $this->assertTrue($newCollection->has('isNot'));
+
+ $this->assertTrue(
+ $collection == $newCollection,
+ '$collection and $newCollection are equal in what they contains'
+ );
+ $this->assertTrue(
+ $collection !== $newCollection,
+ '$collection and $newCollection are not the exact same object'
+ );
+ }
+
+ public function testCanFilterOutAnnotationsAsWell()
+ {
+ $is = new Argil_Util_Annotation_Value('is');
+ $isNot = new Argil_Util_Annotation_Value('isNot');
+
+ $collection = new Argil_Util_Annotation_Collection();
+ $collection->add($is);
+ $collection->add($isNot);
+
+ $this->assertEqual(2, $collection->count(), 'sanity check');
+ $this->assertTrue($collection->has('is'), 'sanity check');
+ $this->assertTrue($collection->has('isNot'), 'sanity check');
+
+ $isOutCollection = $collection->filterOut('is');
+ $this->assertEqual(1, $isOutCollection->count());
+ $this->assertFalse($isOutCollection->has('is'));
+ $this->assertTrue($isOutCollection->has('isNot'));
+
+ $isNotOutCollection = $collection->filterOut('isNot');
+ $this->assertEqual(1, $isNotOutCollection->count());
+ $this->assertTrue($isNotOutCollection->has('is'));
+ $this->assertFalse($isNotOutCollection->has('isNot'));
+ }
+
+ public function testIsAnIterator()
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ $this->assertIsA($collection, 'Iterator');
+
+ $this->assertFalse($collection->valid());
+ $this->assertNull($collection->key());
+ $this->assertNull($collection->current());
+
+ $is = new Argil_Util_Annotation_Value('is');
+ $collection->add($is);
+ $this->assertTrue($collection->valid());
+ $this->assertEqual($collection->current(), $is);
+ $this->assertIdentical($collection->key(), 0);
+
+ $collection->next();
+ $this->assertFalse($collection->valid());
+ $this->assertNull($collection->current());
+ $this->assertNull($collection->key());
+
+ $collection->rewind();
+ $this->assertTrue($collection->valid());
+ $this->assertEqual($collection->current(), $is);
+ $this->assertIdentical($collection->key(), 0);
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 18:52:22
|
Revision: 528
http://argil.svn.sourceforge.net/argil/?rev=528&view=rev
Author: tswicegood
Date: 2007-05-25 11:51:33 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Make second parameter an array only
Modified Paths:
--------------
branches/experimental/src/Argil/Util/Annotation/Value.php
branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
Modified: branches/experimental/src/Argil/Util/Annotation/Value.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 18:44:04 UTC (rev 527)
+++ branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 18:51:33 UTC (rev 528)
@@ -7,7 +7,7 @@
private $_name = null;
private $_params = array();
- public function __construct($name, $params = array())
+ public function __construct($name, array $params = array())
{
if (!is_string($name)) {
throw new Argil_Util_Annotation_Value_Exception(
Modified: branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ValueTest.php 2007-05-25 18:44:04 UTC (rev 527)
+++ branches/experimental/tests/Argil/Util/Annotation/ValueTest.php 2007-05-25 18:51:33 UTC (rev 528)
@@ -71,4 +71,15 @@
$this->assertEqual('non-string provided for name at construct', $e->getMessage());
}
}
+
+ public function testOnlyTakesAnOptionalArrayForSecondParamter()
+ {
+ $refl = new ReflectionClass('Argil_Util_Annotation_Value');
+ $constructor = $refl->getConstructor();
+ $params = $constructor->getParameters();
+
+ $secondParam = $params[1];
+ $this->assertTrue($secondParam->isArray());
+ $this->assertTrue($secondParam->isOptional());
+ }
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 18:44:25
|
Revision: 527
http://argil.svn.sourceforge.net/argil/?rev=527&view=rev
Author: tswicegood
Date: 2007-05-25 11:44:04 -0700 (Fri, 25 May 2007)
Log Message:
-----------
Add in Annotation Value object and tests
Modified Paths:
--------------
branches/experimental/src/Argil/Util/Annotation/Value.php
Added Paths:
-----------
branches/experimental/src/Argil/Util/Annotation/Value/
branches/experimental/src/Argil/Util/Annotation/Value/Exception.php
branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Value/Exception.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value/Exception.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Value/Exception.php 2007-05-25 18:44:04 UTC (rev 527)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_Annotation_Value_Exception extends Exception
+{
+
+}
\ No newline at end of file
Modified: branches/experimental/src/Argil/Util/Annotation/Value.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 00:44:02 UTC (rev 526)
+++ branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 18:44:04 UTC (rev 527)
@@ -1,6 +1,35 @@
<?php
+require_once 'Argil/Util/Annotation/Value/Exception.php';
+
class Argil_Util_Annotation_Value
{
+ private $_name = null;
+ private $_params = array();
+ public function __construct($name, $params = array())
+ {
+ if (!is_string($name)) {
+ throw new Argil_Util_Annotation_Value_Exception(
+ 'non-string provided for name at construct'
+ );
+ }
+ $this->_name = $name;
+ $this->_params = $params;
+ }
+
+ public function __get($key)
+ {
+ switch ($key) {
+ case 'name':
+ case 'params':
+ $real_key = "_{$key}";
+ return $this->$real_key;
+ }
+ }
+
+ public function __set($key, $value)
+ {
+ throw new Argil_Util_Annotation_Value_Exception();
+ }
}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/ValueTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/ValueTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/ValueTest.php 2007-05-25 18:44:04 UTC (rev 527)
@@ -0,0 +1,74 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Value.php';
+
+class Argil_Util_Annotation_ValueTest extends UnitTestCase
+{
+ public function testHasReadOnlyNamePropertyWhichIsSetAsFirstParameterOfConstructor()
+ {
+ $value = new Argil_Util_Annotation_Value('is');
+ $this->assertEqual('is', $value->name);
+
+ try {
+ $value->name = 'something else';
+ $this->fail('Exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ }
+ }
+
+ public function testHasReadOnlyParamsArrayPropertyAsSecondParameter()
+ {
+ $value = new Argil_Util_Annotation_Value('is', array());
+ $this->assertEqual(array(), $value->params);
+ unset($value);
+
+ $array = array('Hello World', 'random' => rand(10, 20));
+ $value = new Argil_Util_Annotation_Value('is', $array);
+ $this->assertEqual($array, $value->params);
+ }
+
+ public function testThrowsExceptionOnNoneStringFirstParameter()
+ {
+ try {
+ new Argil_Util_Annotation_Value(1);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value(array());
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value(123.321);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value(true);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+
+ try {
+ new Argil_Util_Annotation_Value($this);
+ $this->fail('exception not caught');
+ } catch (Argil_Util_Annotation_Value_Exception $e) {
+ $this->pass('exception caught');
+ $this->assertEqual('non-string provided for name at construct', $e->getMessage());
+ }
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-25 00:44:01
|
Revision: 526
http://argil.svn.sourceforge.net/argil/?rev=526&view=rev
Author: tswicegood
Date: 2007-05-24 17:44:02 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Add in the start of some annontation parsing
Added Paths:
-----------
branches/experimental/src/Argil/Util/
branches/experimental/src/Argil/Util/Annotation/
branches/experimental/src/Argil/Util/Annotation/Collection.php
branches/experimental/src/Argil/Util/Annotation/Value.php
branches/experimental/tests/Argil/Util/
branches/experimental/tests/Argil/Util/Annotation/
branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
Added: branches/experimental/src/Argil/Util/Annotation/Collection.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Collection.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Collection.php 2007-05-25 00:44:02 UTC (rev 526)
@@ -0,0 +1,16 @@
+<?php
+
+class Argil_Util_Annotation_Collection
+{
+ private $_stack = array();
+
+ public function add(Argil_Util_Annotation_Value $annontation)
+ {
+ $this->_stack[] = $annotation;
+ }
+
+ public function count()
+ {
+ return count($this->_stack);
+ }
+}
\ No newline at end of file
Added: branches/experimental/src/Argil/Util/Annotation/Value.php
===================================================================
--- branches/experimental/src/Argil/Util/Annotation/Value.php (rev 0)
+++ branches/experimental/src/Argil/Util/Annotation/Value.php 2007-05-25 00:44:02 UTC (rev 526)
@@ -0,0 +1,6 @@
+<?php
+
+class Argil_Util_Annotation_Value
+{
+
+}
\ No newline at end of file
Added: branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php
===================================================================
--- branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php (rev 0)
+++ branches/experimental/tests/Argil/Util/Annotation/CollectionTest.php 2007-05-25 00:44:02 UTC (rev 526)
@@ -0,0 +1,15 @@
+<?php
+
+require_once dirname(__FILE__) . '/../../../config.php';
+require_once 'Argil/Util/Annotation/Collection.php';
+
+class Argil_Util_Annotation_CollectionTest extends UnitTestCase
+{
+ public function testCanBeAddedTo()
+ {
+ $collection = new Argil_Util_Annotation_Collection();
+ $this->assertEqual(0, $collection->count());
+ $collection->add(new MockArgil_Util_Annotation_Value());
+ $this->assertEqual(1, $collection->count());
+ }
+}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-24 23:46:08
|
Revision: 525
http://argil.svn.sourceforge.net/argil/?rev=525&view=rev
Author: tswicegood
Date: 2007-05-24 16:46:10 -0700 (Thu, 24 May 2007)
Log Message:
-----------
Add String Spec to all tests
Modified Paths:
--------------
branches/experimental/tests/AllTest.php
Modified: branches/experimental/tests/AllTest.php
===================================================================
--- branches/experimental/tests/AllTest.php 2007-05-24 01:54:09 UTC (rev 524)
+++ branches/experimental/tests/AllTest.php 2007-05-24 23:46:10 UTC (rev 525)
@@ -10,5 +10,6 @@
$this->addTestFile('Argil/Reflection/PropertyTest.php');
$this->addTestFile('Argil/RouteTest.php');
$this->addTestFile('Argil/Specification/LengthTest.php');
+ $this->addTestFile('Argil/Specification/StringTest.php');
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <tsw...@us...> - 2007-05-24 01:54:09
|
Revision: 524
http://argil.svn.sourceforge.net/argil/?rev=524&view=rev
Author: tswicegood
Date: 2007-05-23 18:54:09 -0700 (Wed, 23 May 2007)
Log Message:
-----------
Add in a quick sanity check just to insure that it's properly loading the String spec
Modified Paths:
--------------
branches/experimental/tests/Argil/Reflection/PropertyTest.php
Modified: branches/experimental/tests/Argil/Reflection/PropertyTest.php
===================================================================
--- branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-05-24 01:50:40 UTC (rev 523)
+++ branches/experimental/tests/Argil/Reflection/PropertyTest.php 2007-05-24 01:54:09 UTC (rev 524)
@@ -68,6 +68,9 @@
$stringReflection = new Argil_Reflection_Property($properties[4]);
$this->assertEqual('string', $stringReflection->getName(), 'sanity check');
+ $object->string = 'hello world';
+ $this->assertTrue($stringReflection->isValid($object), '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.
|