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
Related
If you've worked with Laravel and Lando together, you probably know that Lando gives you its own artisan shortcut. So instead of having to run lando php artisan ..., you can run lando artisan ....
However, when I do that, I get this error:
Could not open input file: /app/./../artisan
This forces me to have to run lando php artisan to run any artisan commands, and that does work fine. So far, this is all that's going wrong with my project in Lando. Everything else is running smoothly.
Here's what my lando config looks like:
name: laravel-project
recipe: laravel
config:
php: '7.4'
composer_version: '2.0.12'
database: mysql:8.0
services:
appserver:
webroot: public
xdebug: true
config:
php: .vscode/php.ini
node:
type: node:14
tooling:
node:
service: node
yarn:
service: node
Also, this does look a bit different from Lando's sample config on their website. This is because I was trying to configure xdebug according to their "Using Lando with VSCode" instructions (see Lando rc.2+ version).
Appreciate any help figuring this weird issue out. It's not debilitating, but it does get in the way when I forget the workaround.
Other notes:
"webroot" is set to "public" because that's where the public-facing directory is for a Laravel app. The example Lando config for Laravel has this part wrong and it causes the project root to be visible to the browser.
I got it working. I moved the webroot key back under the top-level config. Not sure what the difference is, but as long as it works... I guess the only thing I really need to specify in the appserver service is the Xdebug settings.
name: laravel-project
recipe: laravel
config:
php: '7.4'
composer_version: '2.0.12'
webroot: public
database: mysql:8.0
services:
appserver:
xdebug: true
config:
php: .vscode/php.ini
node:
type: node:14
tooling:
node:
service: node
yarn:
service: node
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.
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:
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
I'm just trying to use codeclimate cli to analyze my code locally. I'm using Mac OS X 10.10.3 and, as recommended here, I'm using boot2docker.
Everything good so far. I run codeclimate init to generate .codeclimate.yml file and tweaked it. It looks like this:
---
engines:
phpcodesniffer:
enabled: true
coffeelint:
enabled: true
eslint:
enabled: true
csslint:
enabled: true
ratings:
paths:
- "**.php"
- "**.coffee"
- "**.js"
- "**.jsx"
- "**.css"
exclude_paths:
- node_modules/**/*
- vendor/**/*
- etc/**/*
- .vagrant/**/*
After that I run codeclimate engines:install and this is my output:
Pulling docker images.
WARNING: unknown engine name: phpcodesniffer
...
Finally, codeclimate engines:list outputs:
Available engines:
- bundler-audit: Patch-level verification for Bundler
- coffeelint: A style checker for CoffeeScript
- csslint: Automated linting of Cascading Stylesheets
- eslint: A JavaScript/JSX linting utility
- gofmt: gofmt
- golint: golint
- govet: govet
- rubocop: A Ruby static code analyzer, based on the community Ruby style guide.
- rubymotion: Rubymotion-specific rubocop checks
- watson: A young Ember Doctor to help you fix your code.
What am I doing wrong? How should I install this engine?
Many thanks in advance
We (Code Climate) just recently released the phpcodesniffer engine, and your local Code Climate CLI version likely needs to be updated to know about it.
I just updated our docs to explain how to run an update: http://docs.codeclimate.com/article/301-code-climate-cli-troubleshooting#unknown_engine