public function testSpy() { $dependency = $this->prophesize(\Foo\DependencyInterface::class); $foo = new Foo($dependency->reveal()); $foo->baz(); $dependency->boolGenerator(1)->shouldHaveBeenCalled(); }
public function testMockedMethodIsProxiedToOriginalMethod() { $proxy = $this->getMockBuilder('Bar')->enableProxyingToOriginalMethods()->getMock(); $proxy->expects($this->once())->method('doSomethingElse'); $foo = new Foo(); $this->assertEquals('result', $foo->doSomething($proxy)); }
function main() { $f = new Foo(); var_dump($f->getter()); $f->heh(); var_dump($f->getter()); }
/** * @expectedException Fliglio\Web\ValidationException */ public function testValidationError() { // given $expectedFoo = new Foo("invalid"); // when $expectedFoo->validate(); }
public function testLoadConfigFromFile() { $file = __DIR__ . '/fixtures/configurabletrait-test.php'; $foo = new Foo(); $foo->loadConfigFromFile($file); $this->assertTrue(in_array($file, get_included_files())); }
function baa(Foo $param) { if ($param->valid()) { echo 'valid'; } else { echo 'invalid'; } }
/** * This test function contains a code which will * create a php warning to happen. This eample show * that in phpunit it will treated as an exception and * it could be catched by 'expectedException' tag and * exception name would be 'PHPUnit_Framework_Error' * * @expectedException PHPUnit_Framework_Error */ public function testPhpError() { $foo_obj = new Foo(); # Line below will throw an exception here only $foo_obj->bar(); # Code execution will never reach this point $this->assertTrue(true); }
function test_dynamic_new() { $f = new Foo(); $f->bar(); $k = "Foo"; $g = new $k(); $g->bar(); }
public function testActionKnown() { try { $foo = new Foo(new \Glossary\View()); $foo->action('baz', array()); } catch (Exception $e) { $this->fail(); } }
function main() { $a = new Foo(); $a->identity(232); $a->identity(42); $a->identity(0); add(1, 1); add(0, 0); }
function test() { $e = new Foo(); try { throw new Exception("ops 2"); } catch (Exception $e) { echo $e->getMessage() . "\n"; } }
function main() { // just checking it can be default-constructed... var_dump((new Foo())->getMessage()); $junk = new Exception(); $foo = new Foo('hello, world', 1337, $junk); var_dump($foo->getMessage()); var_dump($foo->getCode()); var_dump($foo->getPrevious() === $junk); }
public function testDeleteAllMethod() { $foo = new Foo(); $foo->setProperty(array('foo' => 'boo', 'bar' => 'moo')); $this->assertEquals(array('foo' => 'boo', 'bar' => 'moo'), $foo->getProperty()); $foo->deleteProperty(); $this->assertEquals(array(), $foo->getProperty()); $this->assertFalse($foo->hasPropertyKey('foo')); $this->assertCount(0, $foo->getProperty()); }
/** * Returns a collection of Foo instances according to * the configuration section. */ public function &process(__ConfigurationSection &$section) { $return_value = array(); $foobars = $section->getSections(); foreach ($foobars as &$foobar) { $foo = new Foo(); $foo->setBar($foobar->getAttribute('bar')); $return_value[] = $foo; } return $return_value; }
public function testContainersPersistBetweenInstances() { $foo1 = new Foo(); $foo1->append('Foo'); $foo1->setSeparator(' - '); $foo2 = new Foo(); $foo2->append('Bar'); $test = $foo1->toString(); $this->assertContains('Foo', $test); $this->assertContains(' - ', $test); $this->assertContains('Bar', $test); }
public function testStaticApiMapper() { // given $entity = new Foo("foo"); $vo = ["myProp" => "foo"]; // when $foundVo = $entity->marshal(); $foundEntity = Foo::unmarshal($vo); // then $this->assertEquals($entity, $foundEntity); $this->assertEquals($vo, $foundVo); }
public function __construct() { parent::__construct(); echo "From ", __METHOD__, ":", "\n"; echo parent::self, "\n"; echo parent::parent, "\n"; }
public function __construct() { parent::__construct(); echo "From ", __METHOD__, ":", PHP_EOL; echo parent::self, PHP_EOL; echo parent::parent, PHP_EOL; }
protected function eraseData() { Foo::truncate(); Bar::truncate(); Baz::truncate(); Bom::truncate(); }
function __destruct() { $this->orStatus(2); if (method_exists(parent, "__destruct")) { parent::__destruct(); } }
function go() { $y = Foo::fun(); var_dump($y); $y = Foo::fun(); var_dump($y); }
public function test_kissmock_usage() { $bar = new BarMock(); $bar->_mock->setMethodReturnValue('methodBar', 'a', 1); $bar->_mock->setMethodReturnValue('methodBar', 'b', 2); $foo = new Foo($bar); $ret1 = $foo->methodFoo(); $ret2 = $foo->methodFoo(); $this->assertEqual($ret1, 'a'); $this->assertEqual($ret2, 'b'); $callCount = $bar->_mock->getMethodCallCount('methodBar'); $this->assertEqual($callCount, 2); $args1 = $bar->_mock->getMethodArgs('methodBar', 1); $args2 = $bar->_mock->getMethodArgs('methodBar', 2); $this->assertEqual($args1[0], 1); $this->assertEqual($args1[1], 'two'); $this->assertEqual($args2[0], 1); $this->assertEqual($args2[1], 'two'); }
public static function invoke(Foo $instance) { // Same class, other instance, direct call. $instance->call(); // Same class, other instance, indirect call. $foo = new Foo(); $foo->call(); // Same class, other instance, indirect call. $x = new Foo(); $y = $x; $z = $y; $z->call(); // Same class, other instance, direct call. (new Foo())->call(); // Other class, other instance, indirect call. $bar = new Bar(); $bar->call(); // Other class, other instance, direct call. (new Bar())->call(); }
function main() { $k = new Foo("something"); echo $k->getX(); echo "\n"; $k->setX("foo"); echo $k->getX(); echo "\n"; $k->setXVerified("string"); echo $k->getX(); echo "\n"; $k->setY(new Bar()); }
/** * Runs the whole test. */ public function test() { require_once DIR_FILES . '/spl/Foo.php'; $foo = new \Foo(); // Right class name $this->assertEquals('Foo', $foo->getClass()); // Setting parameter values $foo->x = 1; $foo->y = true; // Setting a non-existent parameter value $foo->z = 'test'; // Fetching parameter values $this->assertSame(1, $foo->x); $this->assertTrue($foo->y); // Fetching value of a non-existent parameter $this->assertNull($foo->z); // Testing parameter existence $this->assertTrue(isset($foo->x)); $this->assertTrue(isset($foo->y)); $this->assertFalse(isset($foo->z)); // Testing toArray conversion $array = ['x' => 1, 'y' => true]; $this->assertEquals($array, $foo->toArray()); }
/** * Gets the 'foo_with_inline' service. * * This service is shared. * This method always returns the same instance of the service. * * @return \Foo A Foo instance. */ protected function getFooWithInlineService() { $this->services['foo_with_inline'] = $instance = new \Foo(); $instance->setBar($this->get('inlined')); return $instance; }
<?php /** * Another file used for testing */ require_once "newfolder/subdir/things.php"; $b = Foo::bar();
function foo() { //Foo::foo(1, 2); Foo::foo(1, 2)->foobar(); }
function testChainedPropertyAssignmentExpressionHasExpectedEndLine() { Foo::bar(__FUNCTION__)->baz(__FILE__)->value = 'FOOBAR'; }
<?php trait Too { function bar() { $abc = 123; $a = function ($x) use($abc) { $n = func_num_args(); $args = func_get_args(); var_dump($n, $args); }; return $a; } function baz($obj) { $abc = 456; $obj(789); } } class Foo { use Too; } $a = Foo::bar(); Foo::baz($a);