[Argil-svn] SF.net SVN: argil: [544] branches/experimental
Status: Alpha
Brought to you by:
tswicegood
|
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.
|