how to test private / protected class variable when set to default type

  php, php-7.2, phpunit, typeerror, unit-testing

IBase.php

namespace interfaces;
interface IBase {}

FileNavigate.php

class FileNavigate {

 private IBase $f3; // <= line: 5

 public function __construct(IBase $f3, $file = '') {
  $this->f3 = $f3;
  }
}

FileNavigateTest.php

declare(strict_types=1);

use PHPUnitFrameworkTestCase;

class FileNavigateTest extends TestCase {

 public function testInterface() {
   $mock = $this->createMock(interfacesIBase::class);
   $f3_get_FileNavigate = new FileNavigate($mock); // <= line: 10

   $this->assertTrue(true);
 }

}

cmd:

PHPUnit 8.5.21 by Sebastian Bergmann and contributors.                                                         
                                                                                                               
..E...                                                              1 / 1 (100%)                               
                                                                                                               
Time: 8 ms, Memory: 4.00 MB                                                                                   
                                                                                                               
There was 1 error:                                                                                             
                                                                                                               
1) FileNavigateTest::testInterface                                                                             
ParseError: syntax error, unexpected 'IBase' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)    
                                                                                                               
/html/app/v2/FileNavigate.php:5                                                            
/html/tests/FileNavigateTest.php:10                                                                
                                                                                                               
ERRORS!                                                                                                        
Tests: 1, Assertions: 1, Errors: 1.                                                                            
Script ./vendor/bin/phpunit tests handling the test event returned with error code 2                           
Script @test was called via t 

I know the error is in the file "FileNavigate.php" on line 5

Only my IDE works better when I use this notation.

Anyone know how to test it?

Source: Ask PHP

LEAVE A COMMENT