Best Atoum code snippet using logic.testClass
Strict.phpt
Source:Strict.phpt
1<?php2use Tester\Assert;3require __DIR__ . '/bootstrap.php';4class TestClass5{6 use Dibi\Strict;7 public $public;8 protected $protected;9 public static $publicStatic;10 public function publicMethod()11 {}12 public static function publicMethodStatic()13 {}14 protected function protectedMethod()15 {}16 protected static function protectedMethodS()17 {}18 public function getBar()19 {20 return 123;21 }22 public function isFoo()23 {24 return 456;25 }26}27class TestChild extends TestClass28{29 public function callParent()30 {31 parent::callParent();32 }33}34// calling35Assert::exception(function () {36 $obj = new TestClass;37 $obj->undeclared();38}, 'LogicException', 'Call to undefined method TestClass::undeclared().');39Assert::exception(function () {40 TestClass::undeclared();41}, 'LogicException', 'Call to undefined static method TestClass::undeclared().');42Assert::exception(function () {43 $obj = new TestChild;44 $obj->callParent();45}, 'LogicException', 'Call to undefined method parent::callParent().');46Assert::exception(function () {47 $obj = new TestClass;48 $obj->publicMethodX();49}, 'LogicException', 'Call to undefined method TestClass::publicMethodX(), did you mean publicMethod()?');50Assert::exception(function () { // suggest static method51 $obj = new TestClass;52 $obj->publicMethodStaticX();53}, 'LogicException', 'Call to undefined method TestClass::publicMethodStaticX(), did you mean publicMethodStatic()?');54Assert::exception(function () { // suggest only public method55 $obj = new TestClass;56 $obj->protectedMethodX();57}, 'LogicException', 'Call to undefined method TestClass::protectedMethodX().');58// writing59Assert::exception(function () {60 $obj = new TestClass;61 $obj->undeclared = 'value';62}, 'LogicException', 'Attempt to write to undeclared property TestClass::$undeclared.');63Assert::exception(function () {64 $obj = new TestClass;65 $obj->publicX = 'value';66}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicX, did you mean $public?');67Assert::exception(function () { // suggest only non-static property68 $obj = new TestClass;69 $obj->publicStaticX = 'value';70}, 'LogicException', 'Attempt to write to undeclared property TestClass::$publicStaticX.');71Assert::exception(function () { // suggest only public property72 $obj = new TestClass;73 $obj->protectedX = 'value';74}, 'LogicException', 'Attempt to write to undeclared property TestClass::$protectedX.');75// property getter76$obj = new TestClass;77Assert::false(isset($obj->bar));78Assert::same(123, $obj->bar);79Assert::false(isset($obj->foo));80Assert::same(456, $obj->foo);81// reading82Assert::exception(function () {83 $obj = new TestClass;84 $val = $obj->undeclared;85}, 'LogicException', 'Attempt to read undeclared property TestClass::$undeclared.');86Assert::exception(function () {87 $obj = new TestClass;88 $val = $obj->publicX;89}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicX, did you mean $public?');90Assert::exception(function () { // suggest only non-static property91 $obj = new TestClass;92 $val = $obj->publicStaticX;93}, 'LogicException', 'Attempt to read undeclared property TestClass::$publicStaticX.');94Assert::exception(function () { // suggest only public property95 $obj = new TestClass;96 $val = $obj->protectedX;97}, 'LogicException', 'Attempt to read undeclared property TestClass::$protectedX.');98// unset/isset99Assert::exception(function () {100 $obj = new TestClass;101 unset($obj->undeclared);102}, 'LogicException', 'Attempt to unset undeclared property TestClass::$undeclared.');103Assert::false(isset($obj->undeclared));104// extension method105TestClass::extensionMethod('join', $func = function (TestClass $that, $separator) {106 return $that->foo . $separator . $that->bar;107});108$obj = new TestClass;109Assert::same('456*123', $obj->join('*'));...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with testClass on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!