gron                                     Thu, 15 Apr 2010 21:39:20 +0000

Revision: http://svn.php.net/viewvc?view=revision&revision=298062

Log:
Added traits test cases. No engine changes for now. [TRAITS]

#Getting accustomed to the infrastructure.
#Any comments are welcome, especially with regard to syntax and keywords.

Changed paths:
    A   php/php-src/trunk/Zend/tests/traits/
    A   php/php-src/trunk/Zend/tests/traits/bugs/
    A   php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/alias-semantics.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/interfaces.phpt
    A   php/php-src/trunk/Zend/tests/traits/bugs/missing-trait.phpt
    A   
php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt
    A   php/php-src/trunk/Zend/tests/traits/conflict001.phpt
    A   php/php-src/trunk/Zend/tests/traits/conflict002.phpt
    A   php/php-src/trunk/Zend/tests/traits/conflict003.phpt
    A   php/php-src/trunk/Zend/tests/traits/flattening001.phpt
    A   php/php-src/trunk/Zend/tests/traits/flattening002.phpt
    A   php/php-src/trunk/Zend/tests/traits/flattening003.phpt
    A   php/php-src/trunk/Zend/tests/traits/inheritance001.phpt
    A   php/php-src/trunk/Zend/tests/traits/inheritance002.phpt
    A   php/php-src/trunk/Zend/tests/traits/inheritance003.phpt
    A   php/php-src/trunk/Zend/tests/traits/language001.phpt
    A   php/php-src/trunk/Zend/tests/traits/language002.phpt
    A   php/php-src/trunk/Zend/tests/traits/language003.phpt
    A   php/php-src/trunk/Zend/tests/traits/language004.phpt
    A   php/php-src/trunk/Zend/tests/traits/language005.phpt
    A   php/php-src/trunk/Zend/tests/traits/language006.phpt
    A   php/php-src/trunk/Zend/tests/traits/language007.phpt
    A   php/php-src/trunk/Zend/tests/traits/language008a.phpt
    A   php/php-src/trunk/Zend/tests/traits/language008b.phpt
    A   php/php-src/trunk/Zend/tests/traits/language009.phpt
    A   php/php-src/trunk/Zend/tests/traits/language010.phpt
    A   php/php-src/trunk/Zend/tests/traits/language011.phpt

Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods01.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,19 @@
+--TEST--
+Abstract Trait Methods should behave like common abstract methods.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello {
+  public abstract function hello();
+}
+
+class TraitsTest {
+	use THello;
+}
+
+$test = new TraitsTest();
+$test->hello();
+?>
+--EXPECTF--
+Fatal error: Class %s contains %d abstract method and must therefore be declared abstract or implement the remaining methods (%s) in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods02.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,26 @@
+--TEST--
+Abstract Trait Methods should behave like common abstract methods.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello {
+  public abstract function hello();
+}
+
+trait THelloImpl {
+  public function hello() {
+    echo 'Hello';
+  }
+}
+
+class TraitsTest {
+	use THello;
+	use THelloImpl;
+}
+
+$test = new TraitsTest();
+$test->hello();
+?>
+--EXPECTF--
+Hello
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods03.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,22 @@
+--TEST--
+Abstract Trait Methods should behave like common abstract methods.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello {
+  public abstract function hello();
+}
+
+class TraitsTest {
+  use THello;
+  public function hello() {
+    echo 'Hello';
+  }
+}
+
+$test = new TraitsTest();
+$test->hello();
+?>
+--EXPECTF--
+Hello
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/abstract-methods04.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,36 @@
+--TEST--
+Abstract Trait Methods should behave like common abstract methods and
+implementstion may be provided by other traits. Sorting order shouldn't influence result.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello {
+  public abstract function hello();
+}
+
+trait THelloImpl {
+  public function hello() {
+	echo 'Hello';
+  }
+}
+
+class TraitsTest1 {
+	use THello;
+	use THelloImpl;
+}
+
+$test = new TraitsTest1();
+$test->hello();
+
+class TraitsTest2 {
+	use THelloImpl;
+	use THello;
+}
+
+$test = new TraitsTest2();
+$test->hello();
+
+?>
+--EXPECTF--
+HelloHello
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/alias-semantics.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/alias-semantics.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/alias-semantics.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,23 @@
+--TEST--
+Semantic of alias operation is to provide an additional identifier for the method body of the original method.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello {
+  public function a() {
+    echo 'A';
+  }
+}
+
+class TraitsTest {
+	use THello { a as b; }
+}
+
+$test = new TraitsTest();
+$test->a();
+$test->b();
+
+?>
+--EXPECTF--
+AA
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/case-sensitive.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,25 @@
+--TEST--
+Check for problems with case sensitivity in compositions
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait A {
+	public function M1() {}
+	public function M2() {}
+}
+
+trait B {
+	public function M1() {}
+	public function M2() {}
+}
+
+class MyClass {
+	use A;
+	use B;
+}
+?>
+--EXPECTF--
+Warning: Trait method M1 has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d
+
+Warning: Trait method M2 has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/interfaces.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/interfaces.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/interfaces.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,19 @@
+--TEST--
+Make sure trait does not implement an interface.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+interface MyInterface {
+	public function a();
+}
+
+trait THello implements MyInterface {
+  public function a() {
+    echo 'A';
+  }
+}
+
+?>
+--EXPECTF--
+Fatal error: Cannot use 'MyInterface' as interface on 'THello' since it is a Trait in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/missing-trait.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/missing-trait.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/missing-trait.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,15 @@
+--TEST--
+Check error message for missing traits
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+class TraitsTest {
+  use THello;
+}
+
+$test = new TraitsTest();
+
+?>
+--EXPECTF--
+Fatal error: Trait 'THello' not found in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,31 @@
+--TEST--
+Overridding Conflicting Methods should not result in a notice/warning about collisions
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello1 {
+  public function hello() {
+    echo 'Hello';
+  }
+}
+
+trait THello2 {
+  public function hello() {
+    echo 'Hello';
+  }
+}
+
+class TraitsTest {
+  use THello1;
+  use THello2;
+  public function hello() {
+    echo 'Hello';
+  }
+}
+
+$test = new TraitsTest();
+$test->hello();
+?>
+--EXPECTF--
+Hello
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/conflict001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/conflict001.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/conflict001.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,25 @@
+--TEST--
+Method conflict in traits
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello1 {
+  private function hello() {
+    echo 'Hello';
+  }
+}
+
+trait THello2 {
+  private function hello() {
+    echo 'Hello';
+  }
+}
+
+class TraitsTest {
+	use THello1;
+	use THello2;
+}
+?>
+--EXPECTF--
+Warning: Trait method hello has not been applied, because there are collisions with other trait methods on TraitsTest in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/conflict002.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/conflict002.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/conflict002.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,32 @@
+--TEST--
+Overwridden methods do not cause a conflict.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait HelloWorld {
+   public function sayHello() {
+     echo 'Hello World!';
+   }
+}
+
+trait HelloWorld2 {
+   public function sayHello() {
+     echo 'Hello World2!';
+   }
+}
+
+
+class TheWorldIsNotEnough {
+   use HelloWorld;
+   use HelloWorld2;
+   public function sayHello() {
+     echo 'Hello Universe!';
+   }
+}
+
+$o = new TheWorldIsNotEnough();
+$o->sayHello(); // echos Hello Universe!
+?>
+--EXPECTF--
+Hello Universe!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/conflict003.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/conflict003.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/conflict003.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,33 @@
+--TEST--
+Two methods resulting in a conflict, should be reported both.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait A {
+   public function smallTalk() {
+     echo 'a';
+   }
+   public function bigTalk() {
+     echo 'A';
+   }
+}
+
+trait B {
+   public function smallTalk() {
+     echo 'b';
+   }
+   public function bigTalk() {
+     echo 'B';
+   }
+}
+
+class Talker {
+   use A, B;
+}
+
+?>
+--EXPECTF--
+Warning: Trait method smallTalk has not been applied, because there are collisions with other trait methods on Talker in %s on line %d
+
+Warning: Trait method bigTalk has not been applied, because there are collisions with other trait methods on Talker in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/flattening001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/flattening001.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/flattening001.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,42 @@
+--TEST--
+Methods using object properties
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait T1 {
+  public function getText() {
+    return $this->text;
+  }
+}
+
+trait T2 {
+  public function setTextT2($val) {
+    $this->text = $val;
+  }
+}
+
+class TraitsTest {
+  use T1;
+  use T2;
+  private $text = 'test';
+  public function setText($val) {
+    $this->text = $val;
+  }
+}
+
+$o = new TraitsTest();
+var_dump($o->getText());
+
+$o->setText('foo');
+
+var_dump($o->getText());
+
+$o->setText('bar');
+
+var_dump($o->getText());
+?>
+--EXPECTF--
+string(4) "test"
+string(3) "foo"
+string(3) "bar"
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/flattening002.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/flattening002.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/flattening002.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,28 @@
+--TEST--
+parent:: works like in a method defined without traits.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+class Base {
+   public function sayHello() {
+     echo 'Hello ';
+   }
+}
+
+trait SayWorld {
+   public function sayHello() {
+     parent::sayHello();
+     echo 'World!';
+   }
+}
+
+class MyHelloWorld extends Base {
+   use SayWorld;
+}
+
+$o = new MyHelloWorld();
+$o->sayHello();
+?>
+--EXPECTF--
+Hello World!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/flattening003.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/flattening003.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/flattening003.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,32 @@
+--TEST--
+Traits are flattened recurivly.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function sayHello() {
+     echo 'Hello ';
+   }
+}
+
+trait World {
+   public function sayWorld() {
+     echo 'World!';
+   }
+}
+
+trait HelloWorld {
+   use Hello, World;
+}
+
+class MyHelloWorld {
+   use HelloWorld;
+}
+
+$o = new MyHelloWorld();
+$o->sayHello();
+$o->sayWorld();
+?>
+--EXPECTF--
+Hello World!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/inheritance001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/inheritance001.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/inheritance001.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,24 @@
+--TEST--
+Trait method overwridden by a method defined in the class.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait HelloWorld {
+   public function sayHello() {
+     echo 'Hello World!';
+   }
+}
+
+class TheWorldIsNotEnough {
+   use HelloWorld;
+   public function sayHello() {
+     echo 'Hello Universe!';
+   }
+}
+
+$o = new TheWorldIsNotEnough();
+$o->sayHello(); // echos Hello Universe!
+?>
+--EXPECTF--
+Hello Universe!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/inheritance002.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/inheritance002.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/inheritance002.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,27 @@
+--TEST--
+Trait method overriddes base class method
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+class Base {
+   public function sayHello() {
+     echo 'Hello ';
+   }
+}
+
+trait SayWorld {
+   public function sayHello() {
+     echo 'World!';
+   }
+}
+
+class MyHelloWorld extends Base {
+   use SayWorld;
+}
+
+$o = new MyHelloWorld();
+$o->sayHello();
+?>
+--EXPECTF--
+World!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/inheritance003.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/inheritance003.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/inheritance003.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,38 @@
+--TEST--
+Trait method overriddes base class method and satisfies prototype
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+abstract class Base {
+   public abstract function sayHello(array $a);
+}
+
+class SubClass extends Base {
+   public function sayHello(array $a) {
+     echo "World!\n";
+   }
+}
+
+$s = new SubClass();
+$s->sayHello(array());
+
+
+trait SayWorld {
+   public function sayHello(Base $d) {
+     echo 'World!';
+   }
+}
+
+class MyHelloWorld extends Base {
+   use SayWorld;
+}
+
+$o = new MyHelloWorld();
+$o->sayHello(array());
+
+?>
+--EXPECTF--
+World!
+
+Fatal error: Declaration of MyHelloWorld::sayHello() must be compatible with that of Base::sayHello() in %s on line %d

Added: php/php-src/trunk/Zend/tests/traits/language001.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language001.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language001.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,21 @@
+--TEST--
+Single Trait with simple trait method
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait THello {
+  public function hello() {
+    echo 'Hello';
+  }
+}
+
+class TraitsTest {
+	use THello;
+}
+
+$test = new TraitsTest();
+$test->hello();
+?>
+--EXPECTF--
+Hello

Added: php/php-src/trunk/Zend/tests/traits/language002.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language002.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language002.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,32 @@
+--TEST--
+Use multiple traits.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function sayHello() {
+     echo 'Hello ';
+   }
+}
+
+trait World {
+   public function sayWorld() {
+     echo 'World';
+   }
+}
+
+class MyHelloWorld {
+   use Hello, World;
+   public function sayExclamationMark() {
+     echo '!';
+   }
+}
+
+$o = new MyHelloWorld();
+$o->sayHello();
+$o->sayWorld();
+$o->sayExclamationMark();
+?>
+--EXPECTF--
+Hello World!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language003.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language003.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language003.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,29 @@
+--TEST--
+Use instead to solve a conflict.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function saySomething() {
+     echo 'Hello';
+   }
+}
+
+trait World {
+   public function saySomething() {
+     echo 'World';
+   }
+}
+
+class MyHelloWorld {
+   use Hello, World {
+     Hello::saySomething instead World;
+   }
+}
+
+$o = new MyHelloWorld();
+$o->saySomething();
+?>
+--EXPECTF--
+Hello
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language004.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language004.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language004.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,31 @@
+--TEST--
+Use instead to solve a conflict and as to access the method.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function saySomething() {
+     echo 'Hello';
+   }
+}
+
+trait World {
+   public function saySomething() {
+     echo ' World';
+   }
+}
+
+class MyHelloWorld {
+   use Hello, World {
+     Hello::saySomething instead World;
+	 World::saySomething as sayWorld;
+   }
+}
+
+$o = new MyHelloWorld();
+$o->saySomething();
+$o->sayWorld();
+?>
+--EXPECTF--
+Hello World
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language005.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language005.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language005.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,40 @@
+--TEST--
+Use instead to solve a conflict and as to access the method.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait A {
+   public function smallTalk() {
+     echo 'a';
+   }
+   public function bigTalk() {
+     echo 'A';
+   }
+}
+
+trait B {
+   public function smallTalk() {
+     echo 'b';
+   }
+   public function bigTalk() {
+     echo 'B';
+   }
+}
+
+class Talker {
+    use A, B {
+		B::smallTalk instead A;
+		A::bigTalk instead B;
+		B::bigTalk as talk;
+	}
+}
+
+$t = new Talker;
+$t->smallTalk();
+$t->bigTalk();
+$t->talk();
+
+?>
+--EXPECTF--
+bAB
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language006.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language006.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language006.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,31 @@
+--TEST--
+Express requirements of a trait by abstract methods.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function sayHelloWorld() {
+     echo 'Hello'.$this->getWorld();
+   }
+   abstract public function getWorld();
+ }
+
+class MyHelloWorld {
+   private $world;
+   use Hello;
+   public function getWorld() {
+     return $this->world;
+   }
+   public function setWorld($val) {
+     $this->world = $val;
+   }
+}
+
+$o = new MyHelloWorld();
+$o->setWorld(' World!');
+$o->sayHelloWorld();
+
+?>
+--EXPECTF--
+Hello World!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language007.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language007.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language007.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,30 @@
+--TEST--
+Traits can fulfill the requirements of abstract base classes.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+abstract class Base {
+  abstract function sayWorld();
+}
+
+trait Hello {
+   public function sayHello() {
+     echo 'Hello';
+   }
+   public function sayWorld() {
+     echo ' World!';
+   }
+ }
+
+class MyHelloWorld extends Base {
+	use Hello;
+}
+
+$o = new MyHelloWorld();
+$o->sayHello();
+$o->sayWorld();
+
+?>
+--EXPECTF--
+Hello World!
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language008a.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language008a.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language008a.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,23 @@
+--TEST--
+Visibility can be changed with the as aliasing construct as well.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait HelloWorld {
+   public function sayHello() {
+     echo 'Hello World!';
+   }
+}
+
+class MyClass {
+   use HelloWorld { sayHello as protected; }
+}
+
+
+$o = new MyClass;
+$o->sayHello();
+
+?>
+--EXPECTF--
+Fatal error: Call to protected method MyClass::sayHello() from context '' in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language008b.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language008b.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language008b.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,30 @@
+--TEST--
+Visibility can be changed with the as aliasing construct as well.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait HelloWorld {
+   public function sayHello() {
+     echo 'Hello World!';
+   }
+}
+
+class MyClass {
+   use HelloWorld { sayHello as private sayHelloWorld; }
+
+   public function callPrivateAlias() {
+      $this->sayHelloWorld();
+   }
+}
+
+$o = new MyClass();
+$o->sayHello();
+$o->callPrivateAlias();
+$o->sayHelloWorld();
+
+
+?>
+--EXPECTF--
+Hello World!Hello World!
+Fatal error: Call to private method MyClass::sayHelloWorld() from context '' in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language009.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language009.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language009.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,36 @@
+--TEST--
+In instead definitions all trait whose methods are meant to be hidden can be listed.
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait A {
+   public function foo() {
+     echo 'a';
+   }
+}
+
+trait B {
+   public function foo() {
+     echo 'b';
+   }
+}
+
+trait C {
+   public function foo() {
+     echo 'c';
+   }
+}
+
+class Foo {
+    use C, A, B {
+		B::foo instead A, C;
+	}
+}
+
+$t = new Foo;
+$t->foo();
+
+?>
+--EXPECTF--
+b
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language010.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language010.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language010.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,32 @@
+--TEST--
+Aliasing leading to conflict should result in error message
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function hello() {
+     echo 'Hello';
+   }
+}
+
+trait World {
+   public function world() {
+     echo ' World!';
+   }
+}
+
+
+class MyClass {
+   use Hello, World { hello as world; }
+}
+
+$o = new MyClass();
+$o->hello();
+$o->world();
+
+?>
+--EXPECTF--
+Warning: Trait method world has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d
+Hello
+Fatal error: Call to undefined method MyClass::world() in %s on line %d
\ No newline at end of file

Added: php/php-src/trunk/Zend/tests/traits/language011.phpt
===================================================================
--- php/php-src/trunk/Zend/tests/traits/language011.phpt	                        (rev 0)
+++ php/php-src/trunk/Zend/tests/traits/language011.phpt	2010-04-15 21:39:20 UTC (rev 298062)
@@ -0,0 +1,34 @@
+--TEST--
+Aliasing leading to conflict should result in error message
+--FILE--
+<?php
+error_reporting(E_ALL);
+
+trait Hello {
+   public function sayHello() {
+     echo 'Hello';
+   }
+}
+
+trait World {
+   public function sayHello() {
+     echo ' World!';
+   }
+}
+
+
+class MyClass {
+   use Hello, World { sayHello as sayWorld; }
+}
+
+$o = new MyClass();
+$o->sayHello();
+$o->sayWorld();
+
+?>
+--EXPECTF--
+Warning: Trait method sayWorld has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d
+
+Warning: Trait method sayHello has not been applied, because there are collisions with other trait methods on MyClass in %s on line %d
+
+Fatal error: Call to undefined method MyClass::sayHello() in %s on line %d
\ No newline at end of file
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to