i created some tests with PHPUnit and laravel. The tests are running locally successful, but as a gitlab ci job there is an error.
Here is the ci log:
There was 1 failure:
1) Tests\Feature\AuthTest::testAuthLoggedInIsAdmin
Expected status code 200 but received 500.
Failed asserting that false is true.
/builds/XXX/webproject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:55
/builds/XX/webproject/tests/Feature/AuthTest.php:53
For the better debug and finding a solution i need the error trace from the project or the error.log from the webserver.
What is the best practise to debug errors in the ci?
ok, the solution is very simple... i don't delete the question. Here is the solution:
You have to add an artifact to the job. You can set the artifact, that only on failures the artifact is created. If there is an failure on the build, the hole project is dumped to a seperated location. Now you can browse each files on the dump.
.gitlab-ci.yml
stages:
- test
- deploy
php-7.0:
stage: test
type: test
services:
- mysql:latest
image: tetraweb/php:7.0
script:
- bash .gitlab-ci.sh
- php vendor/bin/phpunit --coverage-text --colors=never
artifacts:
when: on_failure
name: "${CI_BUILD_STAGE}_${CI_BUILD_REF_NAME}_FAILED"
paths:
- "."
untracked: false
expire_in: 1 day
deploy:
stage: deploy
# etc...
Here are more informations about artifacts.
You can download the artifacts in the pipelines section in gitlab:
Related
I have my own php image, which I would like to use for my project to run tests on.
container: rela589n/doctrine-event-sourcing-php:latest
services:
test_db:
image: postgres:13-alpine
env:
POSTGRES_DB: des
POSTGRES_USER: des_user
POSTGRES_PASSWORD: p#$$w0rd
steps:
- uses: actions/checkout#v2
- whatever_needed_to_run_tests_inside_container
This fails on checkout action with such error:
EACCES: permission denied, open '/__w/doctrine-event-sourcing/doctrine-event-sourcing/6977c4d4-3881-44e9-804e-ae086752556e.tar.gz'
And this is logical as in fresh docker container there's no such folder structure. What i thought to do is run checkout action inside virtual machine provided runs-on: ubuntu-20.04 and configure volume for docker so that it will have access to code. However I have no idea neither is it a good practice to do this way nor how to implement this. I guess even if it is possible to do this way it won't work for other actions.
Had the same issue when trying to use my own Docker image. In my case, installing everything I need on the fly was not an option, so I had to fix this issue.
It appears that GitHub runs the Docker image with user 1001 named runner and group 121 named docker. After adding the group, adding the user and adding the user to sudoers the problem was solved.
Notice that the checkout path starts with /_w which is strange. If I perform actions/checkout#v2 without my container, the path is /home/runner. Not sure how to solve that yet.
Thanks, this really helped me to find the issue when trying to deploy a CDK project from within a Docker container on Github Actions.
I was getting a permission denied error after checking out the code, and trying to deploy it.
Error: EACCES: permission denied, mkdir '/__w/arm-test/arm-test/cdk.out/asset.7d21b14f781f8b0e4ebb3b30c66614a80f71a2c1637298e5557a97662fce0abe'
This issue had the workaround of running the container with the same user and group as the Github Actions runner, so that it matched with the permissions of the source code directory: https://github.com/actions/runner/issues/691
jobs:
configure:
runs-on: ubuntu-latest
outputs:
uid_gid: ${{ steps.get-user.outputs.uid_gid }}
steps:
- id: get-user
run: echo "::set-output name=uid_gid::$(id -u):$(id -g)"
clone-and-install:
needs: configure
runs-on: ubuntu-latest
container:
image: mcr.microsoft.com/vscode/devcontainers/base:ubuntu
options: --user ${{ needs.configure.outputs.uid_gid }}
steps:
- uses: actions/checkout#v2
I am trying to integrate sonarcloud with Bitbucket pipeline. I have a simple test project with single file named index.php consisting few lines.
I am exactly not sure what method should I follow.
I have created sonar-project.properties files that consists following lines.
sonar.sourceEncoding=UTF-8
sonar.host.url=https://sonarcloud.io/dashboard?id=first_ftp
sonar.projectKey=first_ftp
Here is my yml file
image: aariacarterweir/lamp-gitftp:latest
clone:
depth: full # SonarCloud scanner needs the full history to assign issues properly
definitions:
caches:
sonar: ~/.sonar/cache # Caching SonarCloud artifacts will speed up your build
steps:
- step: &build-test-sonarcloud
name: Build, test and analyze on SonarCloud
caches:
- node
- sonar
script:
- npm install --quiet
- npm run test -- --code-coverage --no-watch --no-progress --browsers=ChromeHeadlessNoSandbox
- pipe: sonarsource/sonarcloud-scan:0.1.5
variables:
SONAR_TOKEN: ${SONAR_TOKEN}
EXTRA_ARGS: '-Dsonar.sources=src -Dsonar.tests=src -Dsonar.test.inclusions="**/testing/**,**/*.spec.ts" -Dsonar.typescript.lcov.reportPaths=coverage/lcov.info'
When I check into sonarcloud website, It tells
The main branch has no lines of code
Can anybody help me how to configure properly sonarcloud with bitbucket for php project.
I've had the same issue - in my case it was because of the name of the project - it was called ---------Test, and apparently, by default, Sonar will treat that as a test assembly and will exclude it from analysis.
Before running code analysis in bitbucket pipelines, you would have to first manually run analysis(only once). By following below steps.
everyone!
I have been trying to configure Codeception 2.3.6 with Laravel 5.3.30 running on PHP 7.0.23 powered by WAMP 3.1.0. My functional test cases are running fine, but when I try to run my acceptance test cases, a new chrome window opens and then closes without doing anything.
The output in the HTML Report is Codeception Results OK(0s), while the output on the command line is:
WelcomeCept: Perform actions and see result (0.00s)
Time: 3.24 seconds, Memory: 22.75MB
OK (1 test, 0 assertions)
HTML report generated in file://D:\wamp\www\myApp\tests/_output\report.html
First I start ChromeDriver with the command
chromedriver --url-base=/wd/hub
Then I start Selenium Standalone Server 3.13.0 with the command:
java -Dwebdriver.chrome.driver="chromedriver" -jar selenium-server-standalone-3.13.0.jar -port 4445
Then I run my acceptance test suite which contains a single test file, with the command:
call vendor/bin/codecept run acceptance --html
My acceptance.suite.yml is:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://lcms.com/
window_size: false # disabled in ChromeDriver
port: 9515
browser: 'chrome'
restart: true
wait: 200
capabilities:
unexpectedAlertBehaviour: 'accept'
webStorageEnabled: true
javascriptEnabled: true
- Laravel5:
part: ORM
cleanup: false # can't wrap into transaction
environment_file: .env
- \Helper\Acceptance
My WelcomeCept.php file, just for testing the configuration, is:
<?php
class WelcomeCept
{
public function welcomeTest(AcceptanceTester $I)
{
$I->wantTo('perform actions and see result');
}
}
Please review my workflow and let me know if I'm doing things incorrectly or am missing something.
Thanks!
Update: Same thing is happening using GeckoDriver or PhantomJS in WebDriver mode. The tests are passing with OK but not performing any actions.
Solved! I tried WelcomeCest instead of WelcomeCept and things have fallen into place.
I've tried configuring Scrutinizer to fail whenever the CodeSniffer analysis returns some errors with no luck.
Here's what I tried so far:
V1:
build:
tests:
override:
command: './vendor/bin/phpcs ./src --report=checkstyle --report-file=cs-data'
analysis:
file: 'cs-data'
format: 'php-cs-checkstyle'
V2:
build:
tests:
override:
- 'phpcs-run'
My tools and build_failure_conditions:
tools:
php_code_sniffer:
config:
standard: "PSR2"
checks:
php:
code_rating: true
duplication: true
build_failure_conditions:
- 'issues.label("coding-style").new.exists'
What's missing?
TLDR; It looks like you're not specifying which folders to scan for errors.
Try using the following:
build:
tests:
override:
- 'phpcs-run --standard=custom/standard/ruleset.xml --ignore=app/*/*/Test/ app/dir1/ app/dir2/ app/other/folder'
Some things that required clarification for me:
scrutinizer currently does not support failing the phpcs command (similar to phpunit) as that would prevent the issues from being displayed in the UI.
the workaround for that is to set-up a failure condition (which you already did) like for example whether there are coding-style issues, then that would fail the build.
I'm currently using:
build_failure_conditions:
- 'issues.label("coding-style").new.exists'
Which makes the inspection look like this
More info about how to set-up failure conditions:
https://scrutinizer-ci.com/docs/configuration/build_status
I have two repo on my machine
API
Codeception repo that tests API
In API repo I have added codeception+c3
"require-dev": {
"codeception/codeception": "2.*",
"codeception/c3": "2.*",
I've also included c3.php inside index.php, but when trying to test it with --coverage I have this error
[PHPUnit_Framework_Exception]
file_get_contents(http://local.api.codeception.com/c3/report/clear): fai
led to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error
Is there ANY online example of remote codecoverage with Codeception?
Here's my configuration for remote codecoverage with Codeception (Project on GitHub).
Steps for running up remote codecoverage collection
1. Make sure that xdebug installed and enabled.
2. Configure codeception.
File codeception.yml (GitHub):
coverage:
enabled: true
c3_url: 'http://%SERVICE_HOST%/index-test.php/'
include:
- web/*
- config/*
- src/*
3. Enable coverage for the suits you need.
File acceptance.suite.yml (GitHub):
coverage:
remote: true
In my example its enabled only for acceptance tests.
4. Include c3.php file in your application bootstrap.
Application bootstrap file index-test.php (GitHub):
// Start the remote code coverage collection.
require_once __DIR__.'/../c3.php';
// autoloader, application running and etc
// ...
5. Run coverage.
$ vendor/bin/codecept run --coverage --coverage-html
By default you can find your reports in tests/_output directory.
Possible issues
1. Output directory not writable (tests/_output).
$ chmod 777 tests/_output
2. Remote codecoverage not printed in console.
It should not be printed. From documentation:
coverage:
remote: true
In this case remote Code Coverage results won’t be merged with local ones, if this option is enabled. Merging is possible only in case a remote and local files have the same path. But in case of running tests on a remote server we are not sure of it.
3. Some other error.
Try to enable debug. If debug enabled, you can get your report or clear it.
curl -o codecoverage.tar "http://localhost:8080/index-test.php/c3/report/html"
End
Sometimes it's not a trivial task. So I hope this will help!
Ok, it was a configuration nightmare, but I've fixed it
Here is example