-
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 #89 from heimrichhannot/test/static-class-util
Add Unit Tests for StaticClassUtil
- Loading branch information
Showing
4 changed files
with
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace StaticUtil; | ||
|
||
use Contao\TestCase\ContaoTestCase; | ||
use HeimrichHannot\UtilsBundle\StaticUtil\StaticClassUtil; | ||
use HeimrichHannot\UtilsBundle\Tests\StaticUtil\StaticClassUtilTestAssets\ExampleClass; | ||
use HeimrichHannot\UtilsBundle\Tests\StaticUtil\StaticClassUtilTestAssets\ExampleClassUsingTrait; | ||
use HeimrichHannot\UtilsBundle\Tests\StaticUtil\StaticClassUtilTestAssets\ExampleTrait; | ||
|
||
class StaticClassUtilTest extends ContaoTestCase | ||
{ | ||
public function testHasTrait() | ||
{ | ||
$this->assertFalse(StaticClassUtil::hasTrait(ExampleClass::class, ExampleTrait::class)); | ||
$this->assertTrue(StaticClassUtil::hasTrait(ExampleClassUsingTrait::class, ExampleTrait::class)); | ||
|
||
$entityWithoutTrait = new ExampleClass(); | ||
$this->assertEquals('no-trait', $entityWithoutTrait->exampleClassMethod('no-trait')); | ||
$this->assertFalse(StaticClassUtil::hasTrait($entityWithoutTrait, ExampleTrait::class)); | ||
|
||
$entityWithTrait = new ExampleClassUsingTrait(); | ||
$this->assertEquals('using-trait', $entityWithTrait->exampleClassUsingTraitMethod('using-trait')); | ||
$this->assertEquals('from-trait', $entityWithTrait->exampleTraitMethod('from-trait')); | ||
$this->assertTrue(StaticClassUtil::hasTrait($entityWithTrait, ExampleTrait::class)); | ||
|
||
$classWithoutTrait = new class { | ||
public function example(): string | ||
{ | ||
return 'test-without-trait'; | ||
} | ||
}; | ||
$this->assertEquals('test-without-trait', $classWithoutTrait->example()); | ||
$this->assertFalse(StaticClassUtil::hasTrait($classWithoutTrait, ExampleTrait::class)); | ||
|
||
$classUsingTrait = new class { | ||
use ExampleTrait; | ||
|
||
public function example(): string | ||
{ | ||
return 'test-with-trait'; | ||
} | ||
}; | ||
$this->assertEquals('test-with-trait', $classUsingTrait->example()); | ||
$this->assertEquals('test-from-trait', $classUsingTrait->exampleTraitMethod('test-from-trait')); | ||
$this->assertTrue(StaticClassUtil::hasTrait($classUsingTrait, ExampleTrait::class)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/StaticUtil/StaticClassUtilTestAssets/ExampleClass.php
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 | ||
|
||
namespace HeimrichHannot\UtilsBundle\Tests\StaticUtil\StaticClassUtilTestAssets; | ||
|
||
class ExampleClass | ||
{ | ||
public function exampleClassMethod(mixed $return = 'example'): mixed | ||
{ | ||
return $return; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/StaticUtil/StaticClassUtilTestAssets/ExampleClassUsingTrait.php
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 | ||
|
||
namespace HeimrichHannot\UtilsBundle\Tests\StaticUtil\StaticClassUtilTestAssets; | ||
|
||
class ExampleClassUsingTrait | ||
{ | ||
use ExampleTrait; | ||
|
||
public function exampleClassUsingTraitMethod(mixed $return = 'example'): mixed | ||
{ | ||
return $return; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/StaticUtil/StaticClassUtilTestAssets/ExampleTrait.php
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 | ||
|
||
namespace HeimrichHannot\UtilsBundle\Tests\StaticUtil\StaticClassUtilTestAssets; | ||
|
||
trait ExampleTrait | ||
{ | ||
public function exampleTraitMethod(mixed $return = 'example'): mixed | ||
{ | ||
return $return; | ||
} | ||
} |