|
| 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