WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
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