name: phpunit-test
description: Adds a test method to tests/FantasticoTest.php following the project's PHPUnit pattern. Use when user says 'add test', 'write test', 'implement test', or when filling in markTestIncomplete stubs. Key capabilities: setUp with env-var credentials, assertion patterns, incomplete test stubs. Do NOT use for creating new test files or testing non-Fantastico classes.
PHPUnit Test
Critical
- Only edit
tests/FantasticoTest.php— never create a new test file. - Use tabs for indentation (not spaces) —
.scrutinizer.ymlenforcesuse_tabs: true. - Every test method requires a
@covers Detain\Fantastico\Fantastico::methodNamePHPDoc tag. - The
$this->objectfixture is already instantiated insetUp()via env vars — never re-instantiate in tests. - When implementing a stub, remove the
@todoline and themarkTestIncompleteblock entirely.
Instructions
Read
tests/FantasticoTest.phpto locate any existingmarkTestIncompletestub for the target method, or find the correct alphabetical insertion point for a new method.Write the PHPDoc block above the method using this exact format:
/** * @covers Detain\Fantastico\Fantastico::methodName */Declare the method as
public function testMethodName()— prefix is alwaystest, followed by the method name with its original casing (e.g.testGetIpList,testValidIp,testIs_type).Call
$this->objectdirectly — it is already connected-ready fromsetUp():public function testGetIpTypes() { $types = $this->object->getIpTypes(); $this->assertTrue(is_array($types), 'returns an array of types'); }Choose assertions matched to the return type documented in
src/Fantastico.php:boolreturn →$this->assertTrue(...)/$this->assertFalse(...)arrayreturn →$this->assertTrue(is_array($result), 'description')- Array with known keys →
$this->assertArrayHasKey('keyName', $result) $this->connectedstate →$this->assertTrue($this->object->connected, 'description')- Invalid-input path (returns
falseor fault array) → assertassertFalse($result)orassertArrayHasKey('faultcode', $result)
If the test requires live SOAP (any method that calls
connect()internally), note thatFANTASTICO_USERNAME/FANTASTICO_PASSWORDenv vars must be set or the SOAP call will fail. If credentials are unavailable, keep/restoremarkTestIncomplete.Verify by running:
vendor/bin/phpunit tests/ -v
Examples
User says: "implement testValidIp"
Actions taken:
- Read
tests/FantasticoTest.php, locate thetestValid_ipstub. - Replace the stub body — remove
markTestIncomplete. Checksrc/Fantastico.php:validIp(): returnsboolviaip2long. - Write assertions for valid and invalid inputs.
Result (replacing lines 88–97 in tests/FantasticoTest.php):
/**
* @covers Detain\Fantastico\Fantastico::validIp
*/
public function testValid_ip()
{
$this->assertTrue($this->object->validIp('192.168.1.1'), 'valid ip should return true');
$this->assertFalse($this->object->validIp('not-an-ip'), 'invalid ip should return false');
}
User says: "add test for isType"
Result (replacing testIs_type stub):
/**
* @covers Detain\Fantastico\Fantastico::isType
*/
public function testIs_type()
{
$this->assertTrue($this->object->isType(\Detain\Fantastico\Fantastico::ALL_TYPES), 'ALL_TYPES is valid');
$this->assertTrue($this->object->isType(\Detain\Fantastico\Fantastico::VPS_TYPES), 'VPS_TYPES is valid');
$this->assertFalse($this->object->isType(99), 'unknown type should return false');
}
Common Issues
Class 'Detain\Fantastico\Fantastico' not found: Runcomposer installfirst to generate the autoloader.SoapFault: Could not connect to hostduring a live-SOAP test:FANTASTICO_USERNAME/FANTASTICO_PASSWORDenv vars are missing or wrong. Set them or add$this->markTestIncomplete('Credentials not configured.')at the top of the test.- Scrutinizer
parameter_doc_commentsfailure: Every public method insrc/Fantastico.phpneeds@paramtags — but test methods intests/are not checked. No@paramneeded on test methods. - Indentation errors from scrutinizer: Tabs only. If your editor auto-converted to spaces, run
unexpand --first-only -t 4 tests/FantasticoTest.phpto convert back. markTestIncompletenot removed after implementation: The@todoPHPDoc line and the entire$this->markTestIncomplete(...)block must both be deleted when implementing a stub.