This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function doSomethingRef(&$o) { | |
$o = null; | |
} | |
function doSomething($o) { | |
$o = null; | |
} | |
$object = new stdClass; | |
// passed by reference | |
doSomethingRef($object); // $object is now null |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class MyMethodOfficiallyDoesNotExist | |
{ | |
public function __call($method, $args) { | |
return true; | |
} | |
} | |
class MockingNotExistingMethodsTest extends PHPUnit_Framework_TestCase | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AutomatedAssignmentOfConstructorParametersTest extends PHPUnit_Framework_TestCase | |
{ | |
public function testParametersAreAssignedBasingOnTheirNames() | |
{ | |
$object = new MyClass(1, 2); | |
$this->assertEquals(1, $object->getFirst()); | |
$this->assertEquals(2, $object->getSecond()); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/test/it/polimi/hermes/LinkedInGroupAdapterTest.java b/test/it/polimi/hermes/LinkedInGroupAdapterTest.java | |
index c769aff..f4142c5 100644 | |
--- a/test/it/polimi/hermes/LinkedInGroupAdapterTest.java | |
+++ b/test/it/polimi/hermes/LinkedInGroupAdapterTest.java | |
@@ -1,44 +1,45 @@ | |
package it.polimi.hermes; | |
import static org.junit.Assert.assertEquals; | |
- | |
+import static org.mockito.Mockito.*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ObjectEncapsulatingState | |
{ | |
private $number; | |
public function __construct($number) | |
{ | |
$this->number = $number; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace IBL { | |
class FranchiseMapper {} | |
} | |
namespace { | |
var_dump(new IBL\FranchiseMapper); | |
$closure = function() { | |
return new IBL\FranchiseMapper; | |
}; | |
var_dump($closure()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Unprintable | |
{ | |
public function __construct($parent = NULL, $nestingLimit = 4) | |
{ | |
$this->parent = $parent; | |
if ($nestingLimit == 0) { | |
return; | |
} | |
for ($i = 0; $i < 10; $i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function byReference(&$d) | |
{ | |
$d = new DateTime('1990-01-01'); | |
} | |
function byValue($d) | |
{ | |
$d = new DateTime('1990-01-01'); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass | |
{ | |
function __construct(Collaborator %collaborator) | |
{ | |
} | |
} | |
// vs. | |
class MyClass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// phake | |
Phake::mock('Namespace\CollaboratorClass') | |
// proposed alternative (atoum) | |
new \mock\Namespace\CollaboratorClass() | |
// Mockito (Java) | |
package Namespace; | |
mock(CollaboratorClass.class); |
OlderNewer