Skip to content
Permalink
Browse files

Assert::with() works with static class

  • Loading branch information...
dg committed Mar 3, 2019
1 parent 6ca248e commit cb737eb52cedf05b318eaefb0cdc0a33e0588f61
Showing with 29 additions and 2 deletions.
  1. +3 βˆ’2 src/Framework/Assert.php
  2. +26 βˆ’0 tests/Framework/Assert.with.phpt
@@ -447,10 +447,11 @@ private static function describe(string $reason, string $description = null): st
/**
* Executes function that can access private and protected members of given object via $this.
* @param object|string $obj
*/
public static function with($obj, \Closure $closure)
public static function with($objectOrClass, \Closure $closure)
{
return $closure->call($obj);
return $closure->bindTo(is_object($objectOrClass) ? $objectOrClass : null, $objectOrClass)();
}
@@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
use Tester\Assert;
require __DIR__ . '/../bootstrap.php';
class Test
{
private static $static = 123;
private $nonstatic = 456;
}
Assert::with(Test::class, function () {
Assert::same(123, self::$static);
});
$test = new Test;
Assert::with($test, function () {
Assert::same(456, $this->nonstatic);
});

0 comments on commit cb737eb

Please sign in to comment.
You can’t perform that action at this time.