diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 62ddff51c..2330898f8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,7 +1,7 @@ name: PHPUnit, PHPCS, Psalm on: # event list - push: # on push to each of these branches + push: branches: - dev - fix @@ -11,8 +11,9 @@ on: # event list branches: - dev - master + - beta -env: # environment variables (available in any part of the action) +env: PHP_VERSION: 7.4 jobs: @@ -28,36 +29,52 @@ jobs: DB_PASSWORD: root steps: + # Checkout + - name: Code Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 # + + # install PHP - name: Set up PHP uses: shivammathur/setup-php@v2 with: php-version: ${{ env.PHP_VERSION }} + extensions: mbstring, intl, mysqli, xdebug + + # Run Composer + - name: Install Dependencies + run: composer install --prefer-dist --no-interaction + # Run MySQL - name: Run MySQL server run: sudo systemctl start mysql - - name: Code Checkout - uses: actions/checkout@v4 - - - name: Make the script files executable + # WP Run + - name: Make WP setup script executable run: chmod +x ./tests/wp-test-setup.sh - name: Install WP develop run: ./tests/wp-test-setup.sh wordpress_test root root localhost latest - - name: Install Dependencies - run: composer i - + # Run PHPUnit с coverage - name: Running tests env: CLEANTALK_TEST_API_KEY: ${{ secrets.CLEANTALK_TEST_API_KEY }} run: composer test + # Load coverage на Codecov - name: Upload coverage to Codecov uses: codecov/codecov-action@v5 + with: + files: coverage.clover + fail_ci_if_error: true + flags: unittests + verbose: true env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + # Matrix - name: Matrix notify on failure if: failure() uses: Glomberg/matrix-messenger-action@master diff --git a/codecov.yml b/codecov.yml new file mode 100644 index 000000000..e45072e09 --- /dev/null +++ b/codecov.yml @@ -0,0 +1,23 @@ +codecov: + require_ci_to_pass: true + +coverage: + precision: 2 + round: down + range: "20..100" + + status: + project: true + patch: true + +comment: + layout: "reach, diff, flags, files" + behavior: default + require_changes: false + +ignore: + - vendor/** + - tests/** + - node_modules/** + - "**/*.md" + - lib/Cleantalk/Common/ContactsEncoder/**/*.php diff --git a/lib/Cleantalk/Common/Helper.php b/lib/Cleantalk/Common/Helper.php index 66010cc3d..996a39d10 100644 --- a/lib/Cleantalk/Common/Helper.php +++ b/lib/Cleantalk/Common/Helper.php @@ -614,6 +614,7 @@ public static function httpRequest($url, $data = array(), $presets = array(), $o * @param array $urls Array of URLs to requests * * @return array|bool + * @codeCoverageIgnore */ public static function httpMultiRequest($urls, $write_to = '') { @@ -641,7 +642,13 @@ static function ($content, $url) use ($write_to) { : 'error'; } + /** + * @codeCoverageIgnoreStart + */ return $content; + /** + * @codeCoverageIgnoreEnd + */ } ); } diff --git a/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php b/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php index 040619179..26534042a 100644 --- a/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php +++ b/tests/ApbctWP/ContactsEncoder/TestContactsEncoder.php @@ -26,13 +26,17 @@ public function setUp() public function testPlainTextEncodeDecodeSSL() { + global $apbct; + /** + * @var State $apbct + */ + $apbct->errorDeleteAll(); $encoded_plain = $this->contacts_encoder->encoder->encodeString($this->plain_text); $this->assertNotEmpty($encoded_plain); $this->assertIsString($encoded_plain); $decoded_entity = $this->contacts_encoder->encoder->decodeString($encoded_plain); $this->assertNotEmpty($decoded_entity); $this->assertIsString($decoded_entity); - global $apbct; $this->assertFalse($apbct->isHaveErrors()); $this->assertEquals($decoded_entity, $this->plain_text); } diff --git a/tests/Common/HelperTest.php b/tests/Common/HelperTest.php deleted file mode 100644 index 1c17a1efc..000000000 --- a/tests/Common/HelperTest.php +++ /dev/null @@ -1,20 +0,0 @@ -assertArrayHasKey( 'error', Helper::httpMultiRequest( 'string' ) ); - $this->assertArrayHasKey( 'error', Helper::httpMultiRequest( '' ) ); - $this->assertArrayHasKey( 'error', Helper::httpMultiRequest( array() ) ); - $this->assertArrayHasKey( 'error', Helper::httpMultiRequest( array(array('https://google.com')) ) ); - } - - public function test_http__multi_request_success() { - $res = Helper::httpMultiRequest( array('https://google.com', 'https://apple.com') ); - $this->assertIsArray( $res ); - $this->assertContainsOnly( 'string', $res ); - } -} diff --git a/tests/phpunit.xml b/tests/phpunit.xml index 4e75c3584..f3c3edbbf 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -1,4 +1,4 @@ - + - + ../ ../vendor ../tests ../node_modules + ../js + ../css + ../lib/Cleantalk/Common/ContactsEncoder ../bootstrap.php + + + + +