diff --git a/tests/StaticUtil/StaticClassUtilTest.php b/tests/StaticUtil/StaticClassUtilTest.php new file mode 100644 index 00000000..b5a31d3a --- /dev/null +++ b/tests/StaticUtil/StaticClassUtilTest.php @@ -0,0 +1,48 @@ +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)); + } +} \ No newline at end of file diff --git a/tests/StaticUtil/StaticClassUtilTestAssets/ExampleClass.php b/tests/StaticUtil/StaticClassUtilTestAssets/ExampleClass.php new file mode 100644 index 00000000..679fffcd --- /dev/null +++ b/tests/StaticUtil/StaticClassUtilTestAssets/ExampleClass.php @@ -0,0 +1,11 @@ +