Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update native_functions.inc.rst #337

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions source/fr/mocking_systems/native_functions.inc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,35 @@ atoum permet de très facilement simuler le comportement des fonctions natives d
->exception(function() { $this->testedInstance->loadConfigFile(); })
;

L'expression ``$this->function->file_exists = …`` permet de définir avec une valeur, une expression ou même une fonction anonyme le comportement souhaité de la fonctionne pour le test.

Exemple avec la fonction native mail() de PHP :

.. code-block:: php

<?php

$that = $this;
$this
->assert('mail')
->given($this->newTestedInstance())
->if($this->function->mail = function (string $to, string $subject, string $message, $headers, string $params = '') use ($that) {
$that
->string($to)
->isNotEmpty()
->boolean(filter_var($to, FILTER_VALIDATE_EMAIL) !== false)
->isTrue()
->string($subject)
->isNotEmpty()
->string($message)
->isNotEmpty()
;

return true;
})
->then

.. important::
On ne peut pas mettre de \\ devant les fonctions à simuler, car atoum s’appuie sur le mécanisme de résolution des espaces de nom de PHP.

Expand Down