Skip to content

Commit 4480bc4

Browse files
claudedeviantintegral
authored andcommitted
test: kill PublicVisibility mutation in TextTrait::setText
Create TextTraitTestClass fixture that uses TextTrait directly without aliasing the setText method. This allows testing the trait's method visibility, which kills the PublicVisibility mutation. The existing tests using PostData don't catch this mutation because PostData aliases setText as traitSetText and provides its own public override.
1 parent 4f0e2a0 commit 4480bc4

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Deviantintegral\Har\Tests\Fixtures;
6+
7+
use Deviantintegral\Har\SharedFields\TextTrait;
8+
9+
/**
10+
* Test fixture class that uses TextTrait directly without aliasing.
11+
*
12+
* This class is used to test the visibility of the trait's methods.
13+
* Unlike PostData and Content which alias setText as traitSetText
14+
* and override with their own public method, this class uses the
15+
* trait's setText directly.
16+
*
17+
* @internal Test fixture only
18+
*/
19+
final class TextTraitTestClass
20+
{
21+
use TextTrait;
22+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Deviantintegral\Har\Tests\Unit\SharedFields;
6+
7+
use Deviantintegral\Har\Tests\Fixtures\TextTraitTestClass;
8+
use PHPUnit\Framework\TestCase;
9+
10+
/**
11+
* @covers \Deviantintegral\Har\SharedFields\TextTrait
12+
*/
13+
class TextTraitTest extends TestCase
14+
{
15+
public function testSetTextIsPublic(): void
16+
{
17+
// This test kills the PublicVisibility mutation in TextTrait::setText
18+
// by using a class that uses the trait WITHOUT aliasing/overriding.
19+
//
20+
// Unlike PostData and Content which alias setText as traitSetText
21+
// and provide their own public setText, TextTraitTestClass uses
22+
// the trait's method directly. If the trait's method becomes
23+
// protected, this test will fail with a fatal error.
24+
$instance = new TextTraitTestClass();
25+
26+
// Calling setText from outside the class - would fail if protected
27+
$result = $instance->setText('test content');
28+
29+
// Verify method chaining works (returns self)
30+
$this->assertSame($instance, $result);
31+
32+
// Verify the text was set
33+
$this->assertTrue($instance->hasText());
34+
$this->assertEquals('test content', $instance->getText());
35+
}
36+
37+
public function testSetTextWithNull(): void
38+
{
39+
$instance = new TextTraitTestClass();
40+
$instance->setText('initial');
41+
$this->assertTrue($instance->hasText());
42+
43+
// Setting null should clear the text
44+
$instance->setText(null);
45+
$this->assertFalse($instance->hasText());
46+
$this->assertNull($instance->getText());
47+
}
48+
49+
public function testHasText(): void
50+
{
51+
$instance = new TextTraitTestClass();
52+
53+
// Initially no text
54+
$this->assertFalse($instance->hasText());
55+
56+
// After setting text
57+
$instance->setText('content');
58+
$this->assertTrue($instance->hasText());
59+
60+
// After clearing text
61+
$instance->setText(null);
62+
$this->assertFalse($instance->hasText());
63+
}
64+
65+
public function testGetText(): void
66+
{
67+
$instance = new TextTraitTestClass();
68+
69+
// Initially null
70+
$this->assertNull($instance->getText());
71+
72+
// After setting
73+
$instance->setText('some text');
74+
$this->assertEquals('some text', $instance->getText());
75+
}
76+
}

0 commit comments

Comments
 (0)