diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..a28973c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,85 @@ +name: Tests + +on: + - push + - pull_request + +jobs: + tests: + runs-on: ubuntu-latest + strategy: + matrix: + php: + - 7.1 + - 7.2 + - 7.3 + - 7.4 + + fail-fast: false + + name: PHP ${{ matrix.php }} tests + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + coverage: none + + - name: Add NewRelic APT source + run: echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list + - name: Add NewRelic APT key + run: wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add - + - name: Update APT + run: sudo apt-get update + - name: Install NewRelic PHP extension + run: sudo apt-get -y install newrelic-php5 + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - run: composer install --no-progress --prefer-dist + - run: composer tests + - if: failure() + run: for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done + shell: bash + + + lowest_dependencies: + name: Lowest Dependencies + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: shivammathur/setup-php@v1 + with: + php-version: 7.1 + coverage: none + + - name: Add NewRelic APT source + run: echo 'deb http://apt.newrelic.com/debian/ newrelic non-free' | sudo tee /etc/apt/sources.list.d/newrelic.list + - name: Add NewRelic APT key + run: wget -O- https://download.newrelic.com/548C16BF.gpg | sudo apt-key add - + - name: Update APT + run: sudo apt-get update + - name: Install NewRelic PHP extension + run: sudo apt-get -y install newrelic-php5 + + - name: Get Composer Cache Directory + id: composer-cache + run: echo "::set-output name=dir::$(composer config cache-files-dir)" + - uses: actions/cache@v1 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - run: composer update --no-progress --prefer-dist --prefer-lowest --prefer-stable + - run: composer tests + - if: failure() + run: for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done + shell: bash diff --git a/composer.json b/composer.json index 3dc8324..6a2f84b 100644 --- a/composer.json +++ b/composer.json @@ -30,17 +30,24 @@ }, "require-dev": { "php-parallel-lint/php-parallel-lint": "^1.2", - "ninjify/coding-standard": "^0.10.0" + "ninjify/coding-standard": "^0.10.0", + "ninjify/nunjuck": "^0.3.0" }, "autoload": { "psr-4": { "Contributte\\NewRelic\\": "src" } }, + "autoload-dev": { + "psr-4": { + "ContributteTests\\NewRelic\\": "tests" + } + }, "scripts": { "lint": "vendor/bin/parallel-lint -e php,phpt src", "cs": "vendor/bin/phpcs --standard=vendor/ninjify/coding-standard/ruleset-gamee.xml --extensions=php,phpt --tab-width=4 -sp src", - "csfix": "vendor/bin/phpcbf --standard=vendor/ninjify/coding-standard/ruleset-gamee.xml --extensions=php,phpt --tab-width=4 -sp src" + "csfix": "vendor/bin/phpcbf --standard=vendor/ninjify/coding-standard/ruleset-gamee.xml --extensions=php,phpt --tab-width=4 -sp src", + "tests": "vendor/bin/tester -s -p php --colors 1 -C tests/Cases" }, "archive": { "exclude": [ diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000..ceeb05b --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +/tmp diff --git a/tests/Cases/NewRelicExtensionTest.php b/tests/Cases/NewRelicExtensionTest.php new file mode 100644 index 0000000..cb23862 --- /dev/null +++ b/tests/Cases/NewRelicExtensionTest.php @@ -0,0 +1,81 @@ +load(function (Compiler $compiler): void { + $compiler->addConfig([ + 'newrelic' => [ + 'enabled' => true, + 'appName' => 'YourApplicationName', + 'license' => 'yourLicenseCode', + 'actionKey' => 'action', + 'logLevel' => [ + 'critical', + 'exception', + 'error', + ], + 'rum' => [ + 'enabled' => 'true', + ], + 'transactionTracer' => [ + 'enabled' => true, + 'detail' => 1, + 'recordSql' => 'obfuscated', + 'slowSql' => true, + 'threshold' => 'apdex_f', + 'stackTraceThreshold' => 500, + 'explainThreshold' => 500, + ], + 'errorCollector' => [ + 'enabled' => true, + 'recordDatabaseErrors' => true, + ], + 'parameters' => [ + 'capture' => false, + 'ignored' => [], + ], + 'custom' => [ + 'parameters' => [ + 'paramName' => 'paramValue', + ], + 'tracers' => [], + ], + ], + ]); + $compiler->addExtension('application', new ApplicationExtension()); + $compiler->addExtension('newrelic', new NewRelicExtension()); + }, [getmypid(), 1]); + + /** @var Container $container */ + $container = new $class(); + + Assert::count(1, $container->findByType(OnRequestCallback::class)); + Assert::count(1, $container->findByType(OnErrorCallback::class)); + } + +} + +(new NewRelicExtensionTest())->run(); diff --git a/tests/Mocks/Application.php b/tests/Mocks/Application.php new file mode 100644 index 0000000..1bc536d --- /dev/null +++ b/tests/Mocks/Application.php @@ -0,0 +1,11 @@ +config; + $builder = $this->getContainerBuilder(); + + $builder->addDefinition('application') + ->setFactory(Application::class); + + $this->compiler->addExportedType(Application::class); + } + +} diff --git a/tests/bootstrap.php b/tests/bootstrap.php new file mode 100644 index 0000000..694bf66 --- /dev/null +++ b/tests/bootstrap.php @@ -0,0 +1,11 @@ +