Symfony supports mocking DNS functions of PHP such as
https://symfony.com/blog/new-in-symfony-3-1-network-mocking-and-dns-sensitive-tests. However, this does not work with Codeception, so another solution is required.
Instead, what must be done is to use an alternative PHP mock package.
Install with the usual
composer require --dev php-mock/php-mock
For reference this is what I have done. Note that the namespace has to match the namespace of the class that calls the DNS function, so in my case it's the Symfony Email Validator.
In my Helper class:
* Class Functional
* Here you can define custom actions
* All public methods declared in helper class will be available in $I
class Functional extends \Codeception\Module
* Mock PHP's DNS functions
* This allows us to allow CheckMX validation during tests,
* but without a DNS lookup (i.e. we don't need a network)
public function mockCheckdnsrr()
$builder = new MockBuilder();
$mock = $builder->build();
And then in my Cest file
* @param \FunctionalTester $i
public function checkEmailValidation(\FunctionalTester $i)
// Do test that includes a DNS lookup here
The mocked function will continue to be mocked in other tests run in the same execution unless you call