-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20156eb
commit 59ce4e3
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Überblick über Basis Testaufgaben | ||
|
||
Allen Testaufgaben gemein ist das Schreiben von Unit Tests.\ | ||
In Klammer am Ende jeder Aufgabe steht zur zeitlichen Orientierung eine ungefähre Abschätzung für Umsetzungsdauer. | ||
|
||
- [Objektorientierte Programmierung](oop.md) (~1h) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Aufgaben zum Thema objektorientiertes Programmieren | ||
|
||
Der Basis Namespace für alle folgenden Beispiele ist `\NiceshopsDev\NiceAcademy\Tests\Basic`. | ||
|
||
## UnitTest schreiben (~5min) | ||
Erweitere den Testfall `NiceClassTest` um einen Test für die Methode `NiceClass::getString`. | ||
|
||
## UnitTest mit Data Provider schreiben (~10min) | ||
Erweitere den Testfall `NiceClassTest` um einen Test für die Methode `NiceClass::result` | ||
mit Hilfe der Anwendung eines Data Providers. | ||
|
||
## Klasse erweitern (~15min) | ||
Erstelle die Klasse `MyNiceClass` welche von der Klasse `NiceClass` ableitet.\ | ||
Die Methode `MyNiceClass::result` soll den String 'always be nice' zurückliefern.\ | ||
Achte dabei darauf so wenig Code wie möglich zu duplizieren. | ||
|
||
Schreib weiters einen Unit Test welcher das erwartete Ergebnis überprüft. | ||
|
||
## Interface implementieren (~15m) | ||
Implementiere für die Klasse `NiceClass` das `\Countable` Interface (https://www.php.net/manual/en/class.countable).\ | ||
Als Ergebnis soll dabei die Anzahl der Zeichen vom Rückgabewert der Methode `NiceClass::result` verwendet werden. | ||
```php | ||
echo count(new NiceClass()); // 7 | ||
``` | ||
|
||
Überprüfe die korrekte Implementierung über entsprechende Unit Tests für die Klassen `NiceClass` und `MyNiceClass`. | ||
|
||
## Methoden Sichtbarkeit ändern (~15m) | ||
Die Methode `NiceClass::getString` soll von außerhalb der Instanz nicht mehr aufgerufen werden können.\ | ||
Achte weiters darauf, dass alle vorhandenen Unit Tests weiterhin funktionieren.\ | ||
(Tipp: https://www.php.net/manual/en/class.reflectionmethod) | ||
```php | ||
$getStringMethod = new \ReflectionMethod($this->object, "getString"); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace NiceshopsDev\NiceAcademy\Tests\Basic; | ||
|
||
|
||
class NiceClass | ||
{ | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getString(): string | ||
{ | ||
return "be "; | ||
} | ||
|
||
|
||
/** | ||
* @return string | ||
*/ | ||
public function result(): string | ||
{ | ||
return trim($this->getString()) . " nice"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace NiceshopsDev\NiceAcademy\Tests\Basic; | ||
|
||
|
||
use PHPUnit\Framework\MockObject\MockObject; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NiceClassTest extends TestCase | ||
{ | ||
|
||
|
||
/** | ||
* @var NiceClass|MockObject | ||
*/ | ||
protected $object; | ||
|
||
|
||
protected function setUp() | ||
{ | ||
$this->object = $this->getMockBuilder(NiceClass::class)->disableOriginalConstructor()->getMockForAbstractClass(); | ||
} | ||
|
||
|
||
/** | ||
* @group integration | ||
* @small | ||
*/ | ||
public function testTestClassExists() | ||
{ | ||
$this->assertTrue(class_exists(NiceClass::class)); | ||
$this->assertTrue($this->object instanceof NiceClass); | ||
} | ||
} |