mirror of
https://github.com/pestphp/pest.git
synced 2026-03-06 07:47:22 +01:00
Merge pull request #962 from JonPurvis/construct-destruct-expectations
add toHaveConstructor() and toHaveDestructor() expectations
This commit is contained in:
@ -862,4 +862,20 @@ final class Expectation
|
|||||||
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
FileLineFinder::where(fn (string $line): bool => str_contains($line, 'class')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target has a constructor method.
|
||||||
|
*/
|
||||||
|
public function toHaveConstructor(): ArchExpectation
|
||||||
|
{
|
||||||
|
return $this->toHaveMethod('__construct');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target has a destructor method.
|
||||||
|
*/
|
||||||
|
public function toHaveDestructor(): ArchExpectation
|
||||||
|
{
|
||||||
|
return $this->toHaveMethod('__destruct');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -469,4 +469,20 @@ final class OppositeExpectation
|
|||||||
implode(' ', array_map(fn (mixed $argument): string => $toString($argument), $arguments)),
|
implode(' ', array_map(fn (mixed $argument): string => $toString($argument), $arguments)),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target does not have a constructor method.
|
||||||
|
*/
|
||||||
|
public function toHaveConstructor(): ArchExpectation
|
||||||
|
{
|
||||||
|
return $this->toHaveMethod('__construct');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the given expectation target does not have a destructor method.
|
||||||
|
*/
|
||||||
|
public function toHaveDestructor(): ArchExpectation
|
||||||
|
{
|
||||||
|
return $this->toHaveMethod('__destruct');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
tests/Features/Expect/toHaveConstructor.php
Normal file
9
tests/Features/Expect/toHaveConstructor.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
test('class has constructor')
|
||||||
|
->expect('Tests\Fixtures\Arch\ToHaveConstructor\HasConstructor\HasConstructor')
|
||||||
|
->toHaveConstructor();
|
||||||
|
|
||||||
|
test('class has no constructor')
|
||||||
|
->expect('Tests\Fixtures\Arch\ToHaveConstructor\HasNoConstructor\HasNoConstructor')
|
||||||
|
->not->toHaveConstructor();
|
||||||
9
tests/Features/Expect/toHaveDestructor.php
Normal file
9
tests/Features/Expect/toHaveDestructor.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
test('class has destructor')
|
||||||
|
->expect('Tests\Fixtures\Arch\ToHaveDestructor\HasDestructor\HasDestructor')
|
||||||
|
->toHaveDestructor();
|
||||||
|
|
||||||
|
test('class has no destructor')
|
||||||
|
->expect('Tests\Fixtures\Arch\ToHaveDestructor\HasNoDestructor\HasNoDestructor')
|
||||||
|
->not->toHaveDestructor();
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveConstructor\HasConstructor;
|
||||||
|
|
||||||
|
class HasConstructor
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveConstructor\HasNoConstructor;
|
||||||
|
|
||||||
|
class HasNoConstructor
|
||||||
|
{
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveDestructor\HasDestructor;
|
||||||
|
|
||||||
|
class HasDestructor
|
||||||
|
{
|
||||||
|
public function __destruct()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Tests\Fixtures\Arch\ToHaveDestructor\HasNoDestructor;
|
||||||
|
|
||||||
|
class HasNoDestructor
|
||||||
|
{
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user