瀏覽代碼

introduce ptest and mockery for testing

jhdxr 2 年之前
父節點
當前提交
3f7731a974
共有 5 個文件被更改,包括 88 次插入0 次删除
  1. 9 0
      composer.json
  2. 18 0
      phpunit.xml
  3. 6 0
      tests/Feature/ExampleTest.php
  4. 45 0
      tests/Pest.php
  5. 10 0
      tests/TestCase.php

+ 9 - 0
composer.json

@@ -38,5 +38,14 @@
     "minimum-stability": "dev",
     "conflict": {
         "ext-swow": "<v1.0.0"
+    },
+    "require-dev": {
+        "pestphp/pest": "2.x-dev",
+        "mockery/mockery": "2.0.x-dev"
+    },
+    "config": {
+        "allow-plugins": {
+            "pestphp/pest-plugin": true
+        }
     }
 }

+ 18 - 0
phpunit.xml

@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd"
+         bootstrap="vendor/autoload.php"
+         colors="true"
+>
+  <testsuites>
+    <testsuite name="Test Suite">
+      <directory suffix="Test.php">./tests</directory>
+    </testsuite>
+  </testsuites>
+  <coverage/>
+  <source>
+    <include>
+      <directory suffix=".php">./src</directory>
+    </include>
+  </source>
+</phpunit>

+ 6 - 0
tests/Feature/ExampleTest.php

@@ -0,0 +1,6 @@
+<?php
+
+test('example', function () {
+    expect(true)->toBeTrue();
+//    expect('3')->toBe(3);
+});

+ 45 - 0
tests/Pest.php

@@ -0,0 +1,45 @@
+<?php
+
+/*
+|--------------------------------------------------------------------------
+| Test Case
+|--------------------------------------------------------------------------
+|
+| The closure you provide to your test functions is always bound to a specific PHPUnit test
+| case class. By default, that class is "PHPUnit\Framework\TestCase". Of course, you may
+| need to change it using the "uses()" function to bind a different classes or traits.
+|
+*/
+
+// uses(Tests\TestCase::class)->in('Feature');
+
+/*
+|--------------------------------------------------------------------------
+| Expectations
+|--------------------------------------------------------------------------
+|
+| When you're writing tests, you often need to check that values meet certain conditions. The
+| "expect()" function gives you access to a set of "expectations" methods that you can use
+| to assert different things. Of course, you may extend the Expectation API at any time.
+|
+*/
+
+expect()->extend('toBeOne', function () {
+    return $this->toBe(1);
+});
+
+/*
+|--------------------------------------------------------------------------
+| Functions
+|--------------------------------------------------------------------------
+|
+| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
+| project that you don't want to repeat in every file. Here you can also expose helpers as
+| global functions to help you to reduce the number of lines of code in your test files.
+|
+*/
+
+function something()
+{
+    // ..
+}

+ 10 - 0
tests/TestCase.php

@@ -0,0 +1,10 @@
+<?php
+
+namespace Tests;
+
+use PHPUnit\Framework\TestCase as BaseTestCase;
+
+abstract class TestCase extends BaseTestCase
+{
+    //
+}