From b501570ab037a12f9fac93ed446a9ea359de40d8 Mon Sep 17 00:00:00 2001 From: Stefan Marr Date: Thu, 15 Apr 2010 21:39:20 +0000 Subject: [PATCH] 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. --- .../tests/traits/bugs/abstract-methods01.phpt | 19 +++++++++ .../tests/traits/bugs/abstract-methods02.phpt | 26 ++++++++++++ .../tests/traits/bugs/abstract-methods03.phpt | 22 ++++++++++ .../tests/traits/bugs/abstract-methods04.phpt | 36 ++++++++++++++++ Zend/tests/traits/bugs/alias-semantics.phpt | 23 ++++++++++ Zend/tests/traits/bugs/case-sensitive.phpt | 25 +++++++++++ Zend/tests/traits/bugs/interfaces.phpt | 19 +++++++++ Zend/tests/traits/bugs/missing-trait.phpt | 15 +++++++ .../bugs/overridding-conflicting-methods.phpt | 31 ++++++++++++++ Zend/tests/traits/conflict001.phpt | 25 +++++++++++ Zend/tests/traits/conflict002.phpt | 32 ++++++++++++++ Zend/tests/traits/conflict003.phpt | 33 +++++++++++++++ Zend/tests/traits/flattening001.phpt | 42 +++++++++++++++++++ Zend/tests/traits/flattening002.phpt | 28 +++++++++++++ Zend/tests/traits/flattening003.phpt | 32 ++++++++++++++ Zend/tests/traits/inheritance001.phpt | 24 +++++++++++ Zend/tests/traits/inheritance002.phpt | 27 ++++++++++++ Zend/tests/traits/inheritance003.phpt | 38 +++++++++++++++++ Zend/tests/traits/language001.phpt | 21 ++++++++++ Zend/tests/traits/language002.phpt | 32 ++++++++++++++ Zend/tests/traits/language003.phpt | 29 +++++++++++++ Zend/tests/traits/language004.phpt | 31 ++++++++++++++ Zend/tests/traits/language005.phpt | 40 ++++++++++++++++++ Zend/tests/traits/language006.phpt | 31 ++++++++++++++ Zend/tests/traits/language007.phpt | 30 +++++++++++++ Zend/tests/traits/language008a.phpt | 23 ++++++++++ Zend/tests/traits/language008b.phpt | 30 +++++++++++++ Zend/tests/traits/language009.phpt | 36 ++++++++++++++++ Zend/tests/traits/language010.phpt | 32 ++++++++++++++ Zend/tests/traits/language011.phpt | 34 +++++++++++++++ 30 files changed, 866 insertions(+) create mode 100644 Zend/tests/traits/bugs/abstract-methods01.phpt create mode 100644 Zend/tests/traits/bugs/abstract-methods02.phpt create mode 100644 Zend/tests/traits/bugs/abstract-methods03.phpt create mode 100644 Zend/tests/traits/bugs/abstract-methods04.phpt create mode 100644 Zend/tests/traits/bugs/alias-semantics.phpt create mode 100644 Zend/tests/traits/bugs/case-sensitive.phpt create mode 100644 Zend/tests/traits/bugs/interfaces.phpt create mode 100644 Zend/tests/traits/bugs/missing-trait.phpt create mode 100644 Zend/tests/traits/bugs/overridding-conflicting-methods.phpt create mode 100644 Zend/tests/traits/conflict001.phpt create mode 100644 Zend/tests/traits/conflict002.phpt create mode 100644 Zend/tests/traits/conflict003.phpt create mode 100644 Zend/tests/traits/flattening001.phpt create mode 100644 Zend/tests/traits/flattening002.phpt create mode 100644 Zend/tests/traits/flattening003.phpt create mode 100644 Zend/tests/traits/inheritance001.phpt create mode 100644 Zend/tests/traits/inheritance002.phpt create mode 100644 Zend/tests/traits/inheritance003.phpt create mode 100644 Zend/tests/traits/language001.phpt create mode 100644 Zend/tests/traits/language002.phpt create mode 100644 Zend/tests/traits/language003.phpt create mode 100644 Zend/tests/traits/language004.phpt create mode 100644 Zend/tests/traits/language005.phpt create mode 100644 Zend/tests/traits/language006.phpt create mode 100644 Zend/tests/traits/language007.phpt create mode 100644 Zend/tests/traits/language008a.phpt create mode 100644 Zend/tests/traits/language008b.phpt create mode 100644 Zend/tests/traits/language009.phpt create mode 100644 Zend/tests/traits/language010.phpt create mode 100644 Zend/tests/traits/language011.phpt diff --git a/Zend/tests/traits/bugs/abstract-methods01.phpt b/Zend/tests/traits/bugs/abstract-methods01.phpt new file mode 100644 index 0000000000..6275caa193 --- /dev/null +++ b/Zend/tests/traits/bugs/abstract-methods01.phpt @@ -0,0 +1,19 @@ +--TEST-- +Abstract Trait Methods should behave like common abstract methods. +--FILE-- +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 diff --git a/Zend/tests/traits/bugs/abstract-methods02.phpt b/Zend/tests/traits/bugs/abstract-methods02.phpt new file mode 100644 index 0000000000..78abe7d1bc --- /dev/null +++ b/Zend/tests/traits/bugs/abstract-methods02.phpt @@ -0,0 +1,26 @@ +--TEST-- +Abstract Trait Methods should behave like common abstract methods. +--FILE-- +hello(); +?> +--EXPECTF-- +Hello \ No newline at end of file diff --git a/Zend/tests/traits/bugs/abstract-methods03.phpt b/Zend/tests/traits/bugs/abstract-methods03.phpt new file mode 100644 index 0000000000..605b1d8e9e --- /dev/null +++ b/Zend/tests/traits/bugs/abstract-methods03.phpt @@ -0,0 +1,22 @@ +--TEST-- +Abstract Trait Methods should behave like common abstract methods. +--FILE-- +hello(); +?> +--EXPECTF-- +Hello \ No newline at end of file diff --git a/Zend/tests/traits/bugs/abstract-methods04.phpt b/Zend/tests/traits/bugs/abstract-methods04.phpt new file mode 100644 index 0000000000..56a3464067 --- /dev/null +++ b/Zend/tests/traits/bugs/abstract-methods04.phpt @@ -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-- +hello(); + +class TraitsTest2 { + use THelloImpl; + use THello; +} + +$test = new TraitsTest2(); +$test->hello(); + +?> +--EXPECTF-- +HelloHello \ No newline at end of file diff --git a/Zend/tests/traits/bugs/alias-semantics.phpt b/Zend/tests/traits/bugs/alias-semantics.phpt new file mode 100644 index 0000000000..ac86692880 --- /dev/null +++ b/Zend/tests/traits/bugs/alias-semantics.phpt @@ -0,0 +1,23 @@ +--TEST-- +Semantic of alias operation is to provide an additional identifier for the method body of the original method. +--FILE-- +a(); +$test->b(); + +?> +--EXPECTF-- +AA \ No newline at end of file diff --git a/Zend/tests/traits/bugs/case-sensitive.phpt b/Zend/tests/traits/bugs/case-sensitive.phpt new file mode 100644 index 0000000000..1d7b77a0c4 --- /dev/null +++ b/Zend/tests/traits/bugs/case-sensitive.phpt @@ -0,0 +1,25 @@ +--TEST-- +Check for problems with case sensitivity in compositions +--FILE-- + +--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 diff --git a/Zend/tests/traits/bugs/interfaces.phpt b/Zend/tests/traits/bugs/interfaces.phpt new file mode 100644 index 0000000000..486bda7efb --- /dev/null +++ b/Zend/tests/traits/bugs/interfaces.phpt @@ -0,0 +1,19 @@ +--TEST-- +Make sure trait does not implement an interface. +--FILE-- + +--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 diff --git a/Zend/tests/traits/bugs/missing-trait.phpt b/Zend/tests/traits/bugs/missing-trait.phpt new file mode 100644 index 0000000000..ce4fa5c69a --- /dev/null +++ b/Zend/tests/traits/bugs/missing-trait.phpt @@ -0,0 +1,15 @@ +--TEST-- +Check error message for missing traits +--FILE-- + +--EXPECTF-- +Fatal error: Trait 'THello' not found in %s on line %d \ No newline at end of file diff --git a/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt b/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt new file mode 100644 index 0000000000..fc09a367bd --- /dev/null +++ b/Zend/tests/traits/bugs/overridding-conflicting-methods.phpt @@ -0,0 +1,31 @@ +--TEST-- +Overridding Conflicting Methods should not result in a notice/warning about collisions +--FILE-- +hello(); +?> +--EXPECTF-- +Hello \ No newline at end of file diff --git a/Zend/tests/traits/conflict001.phpt b/Zend/tests/traits/conflict001.phpt new file mode 100644 index 0000000000..a129b63dae --- /dev/null +++ b/Zend/tests/traits/conflict001.phpt @@ -0,0 +1,25 @@ +--TEST-- +Method conflict in traits +--FILE-- + +--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 diff --git a/Zend/tests/traits/conflict002.phpt b/Zend/tests/traits/conflict002.phpt new file mode 100644 index 0000000000..64712d40a4 --- /dev/null +++ b/Zend/tests/traits/conflict002.phpt @@ -0,0 +1,32 @@ +--TEST-- +Overwridden methods do not cause a conflict. +--FILE-- +sayHello(); // echos Hello Universe! +?> +--EXPECTF-- +Hello Universe! \ No newline at end of file diff --git a/Zend/tests/traits/conflict003.phpt b/Zend/tests/traits/conflict003.phpt new file mode 100644 index 0000000000..5a6d9cf915 --- /dev/null +++ b/Zend/tests/traits/conflict003.phpt @@ -0,0 +1,33 @@ +--TEST-- +Two methods resulting in a conflict, should be reported both. +--FILE-- + +--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 diff --git a/Zend/tests/traits/flattening001.phpt b/Zend/tests/traits/flattening001.phpt new file mode 100644 index 0000000000..aa7f03dcb8 --- /dev/null +++ b/Zend/tests/traits/flattening001.phpt @@ -0,0 +1,42 @@ +--TEST-- +Methods using object properties +--FILE-- +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 diff --git a/Zend/tests/traits/flattening002.phpt b/Zend/tests/traits/flattening002.phpt new file mode 100644 index 0000000000..251af29711 --- /dev/null +++ b/Zend/tests/traits/flattening002.phpt @@ -0,0 +1,28 @@ +--TEST-- +parent:: works like in a method defined without traits. +--FILE-- +sayHello(); +?> +--EXPECTF-- +Hello World! \ No newline at end of file diff --git a/Zend/tests/traits/flattening003.phpt b/Zend/tests/traits/flattening003.phpt new file mode 100644 index 0000000000..d189ca70c1 --- /dev/null +++ b/Zend/tests/traits/flattening003.phpt @@ -0,0 +1,32 @@ +--TEST-- +Traits are flattened recurivly. +--FILE-- +sayHello(); +$o->sayWorld(); +?> +--EXPECTF-- +Hello World! \ No newline at end of file diff --git a/Zend/tests/traits/inheritance001.phpt b/Zend/tests/traits/inheritance001.phpt new file mode 100644 index 0000000000..e8195c4749 --- /dev/null +++ b/Zend/tests/traits/inheritance001.phpt @@ -0,0 +1,24 @@ +--TEST-- +Trait method overwridden by a method defined in the class. +--FILE-- +sayHello(); // echos Hello Universe! +?> +--EXPECTF-- +Hello Universe! \ No newline at end of file diff --git a/Zend/tests/traits/inheritance002.phpt b/Zend/tests/traits/inheritance002.phpt new file mode 100644 index 0000000000..51badc5a4c --- /dev/null +++ b/Zend/tests/traits/inheritance002.phpt @@ -0,0 +1,27 @@ +--TEST-- +Trait method overriddes base class method +--FILE-- +sayHello(); +?> +--EXPECTF-- +World! \ No newline at end of file diff --git a/Zend/tests/traits/inheritance003.phpt b/Zend/tests/traits/inheritance003.phpt new file mode 100644 index 0000000000..ba2e4da76d --- /dev/null +++ b/Zend/tests/traits/inheritance003.phpt @@ -0,0 +1,38 @@ +--TEST-- +Trait method overriddes base class method and satisfies prototype +--FILE-- +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 diff --git a/Zend/tests/traits/language001.phpt b/Zend/tests/traits/language001.phpt new file mode 100644 index 0000000000..d892112416 --- /dev/null +++ b/Zend/tests/traits/language001.phpt @@ -0,0 +1,21 @@ +--TEST-- +Single Trait with simple trait method +--FILE-- +hello(); +?> +--EXPECTF-- +Hello diff --git a/Zend/tests/traits/language002.phpt b/Zend/tests/traits/language002.phpt new file mode 100644 index 0000000000..d093f2952d --- /dev/null +++ b/Zend/tests/traits/language002.phpt @@ -0,0 +1,32 @@ +--TEST-- +Use multiple traits. +--FILE-- +sayHello(); +$o->sayWorld(); +$o->sayExclamationMark(); +?> +--EXPECTF-- +Hello World! \ No newline at end of file diff --git a/Zend/tests/traits/language003.phpt b/Zend/tests/traits/language003.phpt new file mode 100644 index 0000000000..716dda8518 --- /dev/null +++ b/Zend/tests/traits/language003.phpt @@ -0,0 +1,29 @@ +--TEST-- +Use instead to solve a conflict. +--FILE-- +saySomething(); +?> +--EXPECTF-- +Hello \ No newline at end of file diff --git a/Zend/tests/traits/language004.phpt b/Zend/tests/traits/language004.phpt new file mode 100644 index 0000000000..ed176dc2a7 --- /dev/null +++ b/Zend/tests/traits/language004.phpt @@ -0,0 +1,31 @@ +--TEST-- +Use instead to solve a conflict and as to access the method. +--FILE-- +saySomething(); +$o->sayWorld(); +?> +--EXPECTF-- +Hello World \ No newline at end of file diff --git a/Zend/tests/traits/language005.phpt b/Zend/tests/traits/language005.phpt new file mode 100644 index 0000000000..5ee7ab0079 --- /dev/null +++ b/Zend/tests/traits/language005.phpt @@ -0,0 +1,40 @@ +--TEST-- +Use instead to solve a conflict and as to access the method. +--FILE-- +smallTalk(); +$t->bigTalk(); +$t->talk(); + +?> +--EXPECTF-- +bAB \ No newline at end of file diff --git a/Zend/tests/traits/language006.phpt b/Zend/tests/traits/language006.phpt new file mode 100644 index 0000000000..5a32359bb5 --- /dev/null +++ b/Zend/tests/traits/language006.phpt @@ -0,0 +1,31 @@ +--TEST-- +Express requirements of a trait by abstract methods. +--FILE-- +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 diff --git a/Zend/tests/traits/language007.phpt b/Zend/tests/traits/language007.phpt new file mode 100644 index 0000000000..3b65d0123a --- /dev/null +++ b/Zend/tests/traits/language007.phpt @@ -0,0 +1,30 @@ +--TEST-- +Traits can fulfill the requirements of abstract base classes. +--FILE-- +sayHello(); +$o->sayWorld(); + +?> +--EXPECTF-- +Hello World! \ No newline at end of file diff --git a/Zend/tests/traits/language008a.phpt b/Zend/tests/traits/language008a.phpt new file mode 100644 index 0000000000..5a12a4e74b --- /dev/null +++ b/Zend/tests/traits/language008a.phpt @@ -0,0 +1,23 @@ +--TEST-- +Visibility can be changed with the as aliasing construct as well. +--FILE-- +sayHello(); + +?> +--EXPECTF-- +Fatal error: Call to protected method MyClass::sayHello() from context '' in %s on line %d \ No newline at end of file diff --git a/Zend/tests/traits/language008b.phpt b/Zend/tests/traits/language008b.phpt new file mode 100644 index 0000000000..9abbdbeb0d --- /dev/null +++ b/Zend/tests/traits/language008b.phpt @@ -0,0 +1,30 @@ +--TEST-- +Visibility can be changed with the as aliasing construct as well. +--FILE-- +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 diff --git a/Zend/tests/traits/language009.phpt b/Zend/tests/traits/language009.phpt new file mode 100644 index 0000000000..23462e5c17 --- /dev/null +++ b/Zend/tests/traits/language009.phpt @@ -0,0 +1,36 @@ +--TEST-- +In instead definitions all trait whose methods are meant to be hidden can be listed. +--FILE-- +foo(); + +?> +--EXPECTF-- +b \ No newline at end of file diff --git a/Zend/tests/traits/language010.phpt b/Zend/tests/traits/language010.phpt new file mode 100644 index 0000000000..f184457bef --- /dev/null +++ b/Zend/tests/traits/language010.phpt @@ -0,0 +1,32 @@ +--TEST-- +Aliasing leading to conflict should result in error message +--FILE-- +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 diff --git a/Zend/tests/traits/language011.phpt b/Zend/tests/traits/language011.phpt new file mode 100644 index 0000000000..8c4b1a489a --- /dev/null +++ b/Zend/tests/traits/language011.phpt @@ -0,0 +1,34 @@ +--TEST-- +Aliasing leading to conflict should result in error message +--FILE-- +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 -- 2.50.1