Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix regression - partial construction with trait methods (#1403)
Signed-off-by: Nathanael Esayeas <nathanael.esayeas@protonmail.com> Co-authored-by: Ant Weedon <81413869+adnweedon@users.noreply.github.com>
- Loading branch information
1 parent
0d6ae93
commit abe61d7
Showing
4 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fixture\PHP74\Regression\Issue1402; | ||
|
||
/** | ||
* This trait does something, but we need to initialise a thing on construction. | ||
*/ | ||
trait InitTrait { | ||
|
||
protected function init(): void {} | ||
|
||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Fixture\PHP74\Regression\Issue1402; | ||
|
||
class Service { | ||
|
||
use InitTrait; | ||
|
||
private int $arg; | ||
|
||
public function __construct(int $arg) | ||
{ | ||
$this->arg = $arg; | ||
|
||
$this->init(); | ||
} | ||
|
||
public function test(): int | ||
{ | ||
return $this->arg; | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Mockery\Tests\Unit\Regression; | ||
|
||
use Fixture\PHP74\Regression\Issue1402\Service; | ||
use Mockery; | ||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
|
||
/** | ||
* @requires PHP 7.4 | ||
*/ | ||
final class Issue1402Test extends MockeryTestCase | ||
{ | ||
public function testMethod(): void { | ||
$banana = Mockery::mock(Service::class, [1]) | ||
->makePartial(); | ||
|
||
$banana->allows('test')->andReturns(2); | ||
|
||
self::assertEquals(2, $banana->test()); | ||
} | ||
} |