- use mock, spy and stub on your dependancies
- count call expectation (and when it should not be called)
- (try) dont mock what you don't own
- use dataprovider
- test edge case (when function need integer test it with negative / positive / 0 and Infinity)
- test all exit cases (return, exception)
- you can use dummy object to test abstract code
- caution with date, filesystem, external ressources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* This file is part of the Twig Extension TruncateHtmlExtension. | |
* | |
* Author Leon Radley <[email protected]> | |
* Rewrite by Instabledesign | |
* | |
* | |
* Truncate Html string without stripping tags |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#src/AppBundle/Doctrine/ORM/Functions/Greatest.php | |
<?php | |
namespace AppBundle\Doctrine\ORM\Functions; | |
use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
use Doctrine\ORM\Query\AST\PathExpression; | |
use Doctrine\ORM\Query\Lexer; | |
use Doctrine\ORM\Query\Parser; | |
use Doctrine\ORM\Query\SqlWalker; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Adapter | |
Authenticator | |
Accessor | |
Builder | |
Checker | |
Consolidator | |
Controller | |
Container | |
Collector | |
Compiler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#src/AppBundle/Doctrine/DBAL/DateTimeNotConvertable.php | |
<?php | |
namespace AppBundle\Doctrine\DBAL; | |
/** | |
* Class DateTimeNotConvertable | |
* This class was use to skip the automatic DBAL DateTimeUTC transformation | |
* see AppBundle\Doctrine\DBAL\Types\UTCDateTimeType | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package signal_dispatcher | |
import ( | |
"os" | |
"os/signal" | |
) | |
type SignalSubscriber interface { | |
GetSubscribesSignals() *map[os.Signal]bool | |
Notify(os.Signal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package signal | |
import ( | |
"os" | |
"os/signal" | |
) | |
// This is a really small signal subscriber | |
// Signal subscriber that allows you to attach a callback to an `os.Signal` notification. | |
// Usefull to react to any os.Signal. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"net" | |
"net/http" | |
"os" | |
"os/signal" | |
"time" |
Le logger est une dépendance qui peux être considérer comme optionnel.
Il est donc préférable de l'injecter par setter en utilisant le LoggerAwareInterface + LoggerAwareTrait
Il faut ensuite de systématiquement utiliser la syntaxe $this->logger?->...
ℹ️ l'autowire de symfony injecte le logger sur les classe qui implement LoggerAwareInterface https://github.com/symfony/symfony/blob/6.4/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/FrameworkExtension.php#L673-L674
Cette pratique permet d'alleger les définitions de service et aussi de simplifier les Tests