You can use PHPUnit’s –bootstrap switch for this.
--bootstrap <file> A "bootstrap" PHP file that is run before the tests.
Then, make a bootstrap.php file that contains variables:
$port = 4445;
In your tests, you can grab those values:
global $port;
$this->setPort($port);
Then run:
phpunit --bootstrap boot.php MyTest.php