aboutsummaryrefslogtreecommitdiff
path: root/vendors/simpletest/test/interfaces_test.php
diff options
context:
space:
mode:
authorbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-02 18:40:04 +0000
committerbrettp <brettp@36083f99-b078-4883-b0ff-0f9b5a30f544>2009-10-02 18:40:04 +0000
commit322bb9cd2be9e51422cb2b82684692e825c2bfb7 (patch)
tree1e8e75c1ff0c47d6eda9db114a13dfa2b83adf72 /vendors/simpletest/test/interfaces_test.php
parent4ffb02ad9c1b95013a0fbf97cefde827600ecc3f (diff)
downloadelgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.gz
elgg-322bb9cd2be9e51422cb2b82684692e825c2bfb7.tar.bz2
Added simpletest and start of unit tests.
git-svn-id: http://code.elgg.org/elgg/trunk@3503 36083f99-b078-4883-b0ff-0f9b5a30f544
Diffstat (limited to 'vendors/simpletest/test/interfaces_test.php')
-rwxr-xr-xvendors/simpletest/test/interfaces_test.php137
1 files changed, 137 insertions, 0 deletions
diff --git a/vendors/simpletest/test/interfaces_test.php b/vendors/simpletest/test/interfaces_test.php
new file mode 100755
index 000000000..b6980edb1
--- /dev/null
+++ b/vendors/simpletest/test/interfaces_test.php
@@ -0,0 +1,137 @@
+<?php
+// $Id: interfaces_test.php 1699 2008-03-24 16:01:29Z lastcraft $
+require_once(dirname(__FILE__) . '/../autorun.php');
+if (function_exists('spl_classes')) {
+ include(dirname(__FILE__) . '/support/spl_examples.php');
+}
+
+interface DummyInterface {
+ function aMethod();
+ function anotherMethod($a);
+ function &referenceMethod(&$a);
+}
+
+Mock::generate('DummyInterface');
+Mock::generatePartial('DummyInterface', 'PartialDummyInterface', array());
+
+class TestOfMockInterfaces extends UnitTestCase {
+
+ function testCanMockAnInterface() {
+ $mock = new MockDummyInterface();
+ $this->assertIsA($mock, 'SimpleMock');
+ $this->assertIsA($mock, 'MockDummyInterface');
+ $this->assertTrue(method_exists($mock, 'aMethod'));
+ $this->assertTrue(method_exists($mock, 'anotherMethod'));
+ $this->assertNull($mock->aMethod());
+ }
+
+ function testMockedInterfaceExpectsParameters() {
+ $mock = new MockDummyInterface();
+ $mock->anotherMethod();
+ $this->assertError();
+ }
+
+ function testCannotPartiallyMockAnInterface() {
+ $this->assertFalse(class_exists('PartialDummyInterface'));
+ }
+}
+
+class TestOfSpl extends UnitTestCase {
+
+ function skip() {
+ $this->skipUnless(function_exists('spl_classes'), 'No SPL module loaded');
+ }
+
+ function testCanMockAllSplClasses() {
+ if (! function_exists('spl_classes')) {
+ return;
+ }
+ foreach(spl_classes() as $class) {
+ if ($class == 'SplHeap') {
+ continue;
+ }
+ $mock_class = "Mock$class";
+ Mock::generate($class);
+ $this->assertIsA(new $mock_class(), $mock_class);
+ }
+ }
+
+ function testExtensionOfCommonSplClasses() {
+ Mock::generate('IteratorImplementation');
+ $this->assertIsA(
+ new IteratorImplementation(),
+ 'IteratorImplementation');
+ Mock::generate('IteratorAggregateImplementation');
+ $this->assertIsA(
+ new IteratorAggregateImplementation(),
+ 'IteratorAggregateImplementation');
+ }
+}
+
+class WithHint {
+ function hinted(DummyInterface $object) { }
+}
+
+class ImplementsDummy implements DummyInterface {
+ function aMethod() { }
+ function anotherMethod($a) { }
+ function &referenceMethod(&$a) { }
+ function extraMethod($a = false) { }
+}
+Mock::generate('ImplementsDummy');
+
+class TestOfImplementations extends UnitTestCase {
+
+ function testMockedInterfaceCanPassThroughTypeHint() {
+ $mock = new MockDummyInterface();
+ $hinter = new WithHint();
+ $hinter->hinted($mock);
+ }
+
+ function testImplementedInterfacesAreCarried() {
+ $mock = new MockImplementsDummy();
+ $hinter = new WithHint();
+ $hinter->hinted($mock);
+ }
+
+ function testNoSpuriousWarningsWhenSkippingDefaultedParameter() {
+ $mock = new MockImplementsDummy();
+ $mock->extraMethod();
+ }
+}
+
+interface SampleClassWithConstruct {
+ function __construct($something);
+}
+
+class TestOfInterfaceMocksWithConstruct extends UnitTestCase {
+ function testBasicConstructOfAnInterface() {
+ Mock::generate('SampleClassWithConstruct');
+ $this->assertNoErrors();
+ }
+}
+
+interface SampleInterfaceWithHintInSignature {
+ function method(array $hinted);
+}
+
+class TestOfInterfaceMocksWithHintInSignature extends UnitTestCase {
+ function testBasicConstructOfAnInterfaceWithHintInSignature() {
+ Mock::generate('SampleInterfaceWithHintInSignature');
+ $this->assertNoErrors();
+ $mock = new MockSampleInterfaceWithHintInSignature();
+ $this->assertIsA($mock, 'SampleInterfaceWithHintInSignature');
+ }
+}
+
+interface SampleInterfaceWithClone {
+ function __clone();
+}
+
+class TestOfSampleInterfaceWithClone extends UnitTestCase {
+ function testCanMockWithoutErrors() {
+ Mock::generate('SampleInterfaceWithClone');
+ $this->assertNoErrors();
+ }
+}
+?> \ No newline at end of file