generated from spiral-packages/package-skeleton
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from spiral/feature/setup-traits
Adding the ability to use setUp and tearDown methods in traits
- Loading branch information
Showing
15 changed files
with
297 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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
class OtherParentClass extends ParentClass | ||
{ | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
use Spiral\Testing\TestCase; | ||
use Spiral\Testing\Tests\TestCase\Fixture\Trait\WithMethodsTrait; | ||
|
||
class ParentClass extends TestCase | ||
{ | ||
use WithMethodsTrait; | ||
} |
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture\Trait; | ||
|
||
trait WithMethodsTrait | ||
{ | ||
public bool $calledSetUp = false; | ||
public bool $calledTearDown = false; | ||
|
||
public function setUpWithMethodsTrait(): void | ||
{ | ||
$this->calledSetUp = true; | ||
} | ||
|
||
public function tearDownWithMethodsTrait(): void | ||
{ | ||
$this->calledTearDown = true; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture\Trait; | ||
|
||
trait WithSetUpTrait | ||
{ | ||
public bool $calledSetUp = false; | ||
|
||
public function setUpWithSetUpTrait(): void | ||
{ | ||
$this->calledSetUp = true; | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture\Trait; | ||
|
||
trait WithTearDownTrait | ||
{ | ||
public bool $calledTearDown = false; | ||
|
||
public function tearDownWithTearDownTrait(): void | ||
{ | ||
$this->calledTearDown = true; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture\Trait; | ||
|
||
trait WithoutMethodsTrait | ||
{ | ||
public function isAvailable(): bool | ||
{ | ||
return true; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
use Spiral\Testing\TestCase; | ||
use Spiral\Testing\Tests\TestCase\Fixture\Trait\WithMethodsTrait; | ||
|
||
final class WithMethods extends TestCase | ||
{ | ||
use WithMethodsTrait; | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
final class WithMethodsInNestedParent extends OtherParentClass | ||
{ | ||
} |
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,9 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
final class WithMethodsInParent extends ParentClass | ||
{ | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
use Spiral\Testing\TestCase; | ||
use Spiral\Testing\Tests\TestCase\Fixture\Trait\WithSetUpTrait; | ||
|
||
final class WithSetUp extends TestCase | ||
{ | ||
use WithSetUpTrait; | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
use Spiral\Testing\TestCase; | ||
use Spiral\Testing\Tests\TestCase\Fixture\Trait\WithTearDownTrait; | ||
|
||
final class WithTearDown extends TestCase | ||
{ | ||
use WithTearDownTrait; | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
use Spiral\Testing\TestCase; | ||
use Spiral\Testing\Tests\TestCase\Fixture\Trait\WithoutMethodsTrait; | ||
|
||
final class WithoutMethods extends TestCase | ||
{ | ||
use WithoutMethodsTrait; | ||
} |
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase\Fixture; | ||
|
||
use Spiral\Testing\TestCase; | ||
|
||
final class WithoutTraits extends TestCase | ||
{ | ||
} |
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,95 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\Testing\Tests\TestCase; | ||
|
||
use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; | ||
use PHPUnit\Framework\TestCase; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithMethods; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithMethodsInNestedParent; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithMethodsInParent; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithoutMethods; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithoutTraits; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithSetUp; | ||
use Spiral\Testing\Tests\TestCase\Fixture\WithTearDown; | ||
|
||
final class TestCaseTest extends TestCase | ||
{ | ||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
#[DoesNotPerformAssertions] | ||
public function testItDoesNotThrowWhenCallingSetUp(): void | ||
{ | ||
$testCase = new WithoutTraits('foo'); | ||
$testCase->setUp(); | ||
} | ||
|
||
/** | ||
* @doesNotPerformAssertions | ||
*/ | ||
#[DoesNotPerformAssertions] | ||
public function testItDoesNotThrowWhenCallingTearDown(): void | ||
{ | ||
$testCase = new WithoutTraits('foo'); | ||
$testCase->tearDown(); | ||
} | ||
|
||
public function testTraitWithoutMethods(): void | ||
{ | ||
$testCase = new WithoutMethods('foo'); | ||
$testCase->setUp(); | ||
$testCase->tearDown(); | ||
|
||
$this->assertTrue($testCase->isAvailable()); | ||
} | ||
|
||
public function testTraitWithSetUp(): void | ||
{ | ||
$testCase = new WithSetUp('foo'); | ||
$testCase->setUp(); | ||
$testCase->tearDown(); | ||
|
||
$this->assertTrue($testCase->calledSetUp); | ||
} | ||
|
||
public function testTraitWithTearDown(): void | ||
{ | ||
$testCase = new WithTearDown('foo'); | ||
$testCase->setUp(); | ||
$testCase->tearDown(); | ||
|
||
$this->assertTrue($testCase->calledTearDown); | ||
} | ||
|
||
public function testTraitWithSetUpAndTearDownMethods(): void | ||
{ | ||
$testCase = new WithMethods('foo'); | ||
$testCase->setUp(); | ||
$testCase->tearDown(); | ||
|
||
$this->assertTrue($testCase->calledSetUp); | ||
$this->assertTrue($testCase->calledTearDown); | ||
} | ||
|
||
public function testTraitWithSetUpAndTearDownMethodsInParentClass(): void | ||
{ | ||
$testCase = new WithMethodsInParent('foo'); | ||
$testCase->setUp(); | ||
$testCase->tearDown(); | ||
|
||
$this->assertTrue($testCase->calledSetUp); | ||
$this->assertTrue($testCase->calledTearDown); | ||
} | ||
|
||
public function testTraitWithSetUpAndTearDownMethodsInNestedParentClass(): void | ||
{ | ||
$testCase = new WithMethodsInNestedParent('foo'); | ||
$testCase->setUp(); | ||
$testCase->tearDown(); | ||
|
||
$this->assertTrue($testCase->calledSetUp); | ||
$this->assertTrue($testCase->calledTearDown); | ||
} | ||
} |