diff --git a/tests/aot/abstract-class.phpt b/tests/aot/abstract-class.phpt new file mode 100644 index 00000000..65b14682 --- /dev/null +++ b/tests/aot/abstract-class.phpt @@ -0,0 +1,57 @@ +--TEST-- +abstract class and abstract method +--FILE-- +name = $name; + } + + abstract public function speak(): string; + + public function getName(): string { + return $this->name; + } + + public function describe(): string { + return $this->getName() . " says " . $this->speak(); + } +} + +class Dog extends Animal { + public function speak(): string { + return "woof"; + } +} + +class Cat extends Animal { + public function speak(): string { + return "meow"; + } +} + +function main() { + $dog = new Dog("Buddy"); + $cat = new Cat("Kitty"); + + var_dump($dog->getName()); + var_dump($dog->speak()); + var_dump($dog->describe()); + + var_dump($cat->getName()); + var_dump($cat->speak()); + + echo "done\n"; +} + +?> +--EXPECT-- +string(5) "Buddy" +string(4) "woof" +string(15) "Buddy says woof" +string(5) "Kitty" +string(4) "meow" +done diff --git a/tests/aot/backtick.phpt b/tests/aot/backtick.phpt new file mode 100644 index 00000000..905fe1a4 --- /dev/null +++ b/tests/aot/backtick.phpt @@ -0,0 +1,21 @@ +--TEST-- +shell_exec / backtick operator +--FILE-- + +--EXPECT-- +string(5) "hello" +string(5) "world" +done diff --git a/tests/aot/eval-test.phpt b/tests/aot/eval-test.phpt new file mode 100644 index 00000000..89632f7e --- /dev/null +++ b/tests/aot/eval-test.phpt @@ -0,0 +1,30 @@ +--TEST-- +eval() language construct +--FILE-- + +--EXPECT-- +int(15) +string(11) "hello world" +int(6) +done diff --git a/tests/aot/final-class.phpt b/tests/aot/final-class.phpt new file mode 100644 index 00000000..f5dcec27 --- /dev/null +++ b/tests/aot/final-class.phpt @@ -0,0 +1,50 @@ +--TEST-- +final class and final method +--FILE-- +overridable()); + var_dump($base->locked()); + + $derived = new Derived(); + var_dump($derived->overridable()); + var_dump($derived->locked()); + + $sealed = new Sealed(); + var_dump($sealed->value()); + + echo "done\n"; +} + +?> +--EXPECT-- +string(4) "base" +string(15) "cannot override" +string(7) "derived" +string(15) "cannot override" +int(42) +done diff --git a/tests/aot/interface.phpt b/tests/aot/interface.phpt new file mode 100644 index 00000000..8ad403b8 --- /dev/null +++ b/tests/aot/interface.phpt @@ -0,0 +1,65 @@ +--TEST-- +interface implementation +--FILE-- +entries[] = $message; + } + + public function format(string $message): string { + return '{"msg":"' . $message . '"}'; + } + + public function getEntries(): array { + return $this->entries; + } +} + +function main() { + $console = new ConsoleLogger(); + $console->log("test message"); + + $json = new JsonLogger(); + $json->log("hello"); + $json->log("world"); + var_dump($json->getEntries()); + var_dump($json->format("hi")); + + $logger = $json; + var_dump($logger instanceof Logger); + var_dump($logger instanceof Formatter); + + echo "done\n"; +} + +?> +--EXPECT-- +LOG: test message +array(2) { + [0]=> + string(5) "hello" + [1]=> + string(5) "world" +} +string(12) "{"msg":"hi"}" +bool(true) +bool(true) +done