Skip to content

Commit a360857

Browse files
Merge pull request #35 from DaveLiddament/fix/samples-for-test-tags
FIX example code for TestTag on a class
2 parents b64b35e + afa20ee commit a360857

8 files changed

+165
-83
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace TestTagClassOnConstructor;
4+
5+
use DaveLiddament\PhpLanguageExtensions\TestTag;
6+
7+
#[TestTag]
8+
class Person
9+
{
10+
public function __construct()
11+
{
12+
}
13+
14+
public static function create(): Person
15+
{
16+
return new Person(); // OK - whole class is marked with TestTag, so OK to call methods within it.
17+
}
18+
19+
public static function createSelf(): self
20+
{
21+
return new self(); // OK - whole class is marked with TestTag, so OK to call methods within it.
22+
}
23+
}
24+
25+
class AnotherClass
26+
{
27+
public function buildPerson(): Person
28+
{
29+
return new Person(); // ERROR
30+
}
31+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace TestTagClassOnConstructorIgnoredInTestClass;
4+
5+
use DaveLiddament\PhpLanguageExtensions\TestTag;
6+
7+
#[TestTag]
8+
class Person
9+
{
10+
public function __construct()
11+
{
12+
}
13+
}
14+
15+
class PersonTest
16+
{
17+
public function buildPerson(): Person
18+
{
19+
return new Person(); // OK TetTag called from a test class
20+
}
21+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TestTagClassOnMethod;
6+
7+
use DaveLiddament\PhpLanguageExtensions\TestTag;
8+
9+
#[TestTag]
10+
class Person
11+
{
12+
public function updateName(): void
13+
{
14+
}
15+
16+
public function update(): void
17+
{
18+
$this->updateName(); // OK - whole class is marked with TestTag, so OK to call methods within it.
19+
}
20+
}
21+
22+
class Updater
23+
{
24+
public function updater(Person $person): void
25+
{
26+
$person->updateName(); // ERROR
27+
}
28+
}
29+
30+
$person = new Person();
31+
$person->updateName(); // ERROR
32+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace TestTagClassOnMethodIgnoredInTestClass;
6+
7+
use DaveLiddament\PhpLanguageExtensions\TestTag;
8+
9+
#[TestTag]
10+
class Person
11+
{
12+
public function updateName(): void
13+
{
14+
}
15+
}
16+
17+
class PersonTest
18+
{
19+
public function updater(Person $person): void
20+
{
21+
$person->updateName(); // OK - Called from Test class
22+
}
23+
}
24+
25+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace TestTagClassOnStaticMethod;
4+
5+
6+
use DaveLiddament\PhpLanguageExtensions\TestTag;
7+
8+
#[TestTag]
9+
class Person
10+
{
11+
public static function updateName(): void
12+
{
13+
}
14+
15+
public static function update(): void
16+
{
17+
Person::updateName(); // OK - whole class is marked with TestTag, so OK to call methods within it.
18+
}
19+
20+
public static function updateSelf(): void
21+
{
22+
self::updateName(); // OK - whole class is marked with TestTag, so OK to call methods within it.
23+
}
24+
}
25+
26+
class Updater
27+
{
28+
public function updater(): void
29+
{
30+
Person::updateName(); // ERROR
31+
}
32+
}
33+
34+
Person::updateName(); // ERROR
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace TestTagClassOnStaticMethodIgnoredInTestClass;
4+
5+
6+
use DaveLiddament\PhpLanguageExtensions\TestTag;
7+
8+
#[TestTag]
9+
class Person
10+
{
11+
public static function updateName(): void
12+
{
13+
}
14+
}
15+
16+
class PersonTest
17+
{
18+
public function updater(): void
19+
{
20+
Person::updateName(); // OK - Called from a test class
21+
}
22+
}

examples/testTag/testTagOnClass.php

Lines changed: 0 additions & 43 deletions
This file was deleted.

examples/testTag/testTagOnClassIgnoredInTestClass.php

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)