Skip to content

Commit

Permalink
Merge pull request #35 from DaveLiddament/fix/samples-for-test-tags
Browse files Browse the repository at this point in the history
FIX example code for TestTag on a class
  • Loading branch information
DaveLiddament authored Aug 12, 2024
2 parents b64b35e + afa20ee commit a360857
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 83 deletions.
31 changes: 31 additions & 0 deletions examples/testTag/testTagClassOnConstructor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace TestTagClassOnConstructor;

use DaveLiddament\PhpLanguageExtensions\TestTag;

#[TestTag]
class Person
{
public function __construct()
{
}

public static function create(): Person
{
return new Person(); // OK - whole class is marked with TestTag, so OK to call methods within it.
}

public static function createSelf(): self
{
return new self(); // OK - whole class is marked with TestTag, so OK to call methods within it.
}
}

class AnotherClass
{
public function buildPerson(): Person
{
return new Person(); // ERROR
}
}
21 changes: 21 additions & 0 deletions examples/testTag/testTagClassOnConstructorIgnoredInTestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace TestTagClassOnConstructorIgnoredInTestClass;

use DaveLiddament\PhpLanguageExtensions\TestTag;

#[TestTag]
class Person
{
public function __construct()
{
}
}

class PersonTest
{
public function buildPerson(): Person
{
return new Person(); // OK TetTag called from a test class
}
}
32 changes: 32 additions & 0 deletions examples/testTag/testTagClassOnMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace TestTagClassOnMethod;

use DaveLiddament\PhpLanguageExtensions\TestTag;

#[TestTag]
class Person
{
public function updateName(): void
{
}

public function update(): void
{
$this->updateName(); // OK - whole class is marked with TestTag, so OK to call methods within it.
}
}

class Updater
{
public function updater(Person $person): void
{
$person->updateName(); // ERROR
}
}

$person = new Person();
$person->updateName(); // ERROR

25 changes: 25 additions & 0 deletions examples/testTag/testTagClassOnMethodIgnoredInTestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace TestTagClassOnMethodIgnoredInTestClass;

use DaveLiddament\PhpLanguageExtensions\TestTag;

#[TestTag]
class Person
{
public function updateName(): void
{
}
}

class PersonTest
{
public function updater(Person $person): void
{
$person->updateName(); // OK - Called from Test class
}
}


34 changes: 34 additions & 0 deletions examples/testTag/testTagClassOnStaticMethod.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace TestTagClassOnStaticMethod;


use DaveLiddament\PhpLanguageExtensions\TestTag;

#[TestTag]
class Person
{
public static function updateName(): void
{
}

public static function update(): void
{
Person::updateName(); // OK - whole class is marked with TestTag, so OK to call methods within it.
}

public static function updateSelf(): void
{
self::updateName(); // OK - whole class is marked with TestTag, so OK to call methods within it.
}
}

class Updater
{
public function updater(): void
{
Person::updateName(); // ERROR
}
}

Person::updateName(); // ERROR
22 changes: 22 additions & 0 deletions examples/testTag/testTagClassOnStaticMethodIgnoredInTestClass.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace TestTagClassOnStaticMethodIgnoredInTestClass;


use DaveLiddament\PhpLanguageExtensions\TestTag;

#[TestTag]
class Person
{
public static function updateName(): void
{
}
}

class PersonTest
{
public function updater(): void
{
Person::updateName(); // OK - Called from a test class
}
}
43 changes: 0 additions & 43 deletions examples/testTag/testTagOnClass.php

This file was deleted.

40 changes: 0 additions & 40 deletions examples/testTag/testTagOnClassIgnoredInTestClass.php

This file was deleted.

0 comments on commit a360857

Please sign in to comment.