Pest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /*
  3. |--------------------------------------------------------------------------
  4. | Test Case
  5. |--------------------------------------------------------------------------
  6. |
  7. | The closure you provide to your test functions is always bound to a specific PHPUnit test
  8. | case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
  9. | need to change it using the "uses()" function to bind a different classes or traits.
  10. |
  11. */
  12. // uses(Tests\TestCase::class)->in('Feature');
  13. /*
  14. |--------------------------------------------------------------------------
  15. | Expectations
  16. |--------------------------------------------------------------------------
  17. |
  18. | When you're writing tests, you often need to check that values meet certain conditions. The
  19. | "expect()" function gives you access to a set of "expectations" methods that you can use
  20. | to assert different things. Of course, you may extend the Expectation API at any time.
  21. |
  22. */
  23. use Workerman\Connection\TcpConnection;
  24. expect()->extend('toBeOne', function () {
  25. return $this->toBe(1);
  26. });
  27. /*
  28. |--------------------------------------------------------------------------
  29. | Functions
  30. |--------------------------------------------------------------------------
  31. |
  32. | While Pest is very powerful out-of-the-box, you may have some testing code specific to your
  33. | project that you don't want to repeat in every file. Here you can also expose helpers as
  34. | global functions to help you to reduce the number of lines of code in your test files.
  35. |
  36. */
  37. function something()
  38. {
  39. // ..
  40. }
  41. function testWithConnectionClose(Closure $closure, string $dataContains = null, $connectionClass = TcpConnection::class): void
  42. {
  43. $tcpConnection = Mockery::spy($connectionClass);
  44. $closure($tcpConnection);
  45. if ($dataContains) {
  46. $tcpConnection->shouldHaveReceived('close', function ($actual) use ($dataContains) {
  47. return str_contains($actual, $dataContains);
  48. });
  49. } else {
  50. $tcpConnection->shouldHaveReceived('close');
  51. }
  52. }