BitBucket pipeline fails on test cases - php

I'm having hard time to configure a BitBucket pipeline to deploy a CakePHP application to a hosting server.
Reading some tutorials I've ended up with this pipeline:
image: edbizarro/bitbucket-pipelines-php7
pipelines:
branches:
master:
- step:
caches:
- composer
script:
- composer install --no-interaction --no-progress --prefer-dist
- composer test
- composer deploy-to-production
but it always fails:
Build setup -> OK
composer install -> OK
composer test -> FAIL
+composer test
phpunit --colors=always
Deprecated Error: Plugin::load() is deprecated. Use Application::addPlugin() instead. This method will be removed in 4.0.0. - /opt/atlassian/pipelines/agent/build/config/bootstrap.php, line: 179
You can disable deprecation warnings by setting Error.errorLevel to E_ALL & ~E_USER_DEPRECATED in your config/app.php. in [/opt/atlassian/pipelines/agent/build/vendor/cakephp/cakephp/src/Core/functions.php, line 311]
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
Exception: Unable to insert fixtures for "App\Test\TestCase\Controller\CustomersControllerTest" test case. SQLSTATE[HY000] [2002] No such file or directory in [/opt/atlassian/pipelines/agent/build/vendor/cakephp/cakephp/src/TestSuite/Fixture/FixtureManager.php, line 380]
Script phpunit --colors=always handling the test event returned with error code 244
I cannot ls the virtual remote folders but I can mine... so I inspected App\Test\TestCase\Controller\CustomersControllerTest:
<?php
namespace App\Test\TestCase\Controller;
use App\Controller\CustomersController;
use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;
class CustomersControllerTest extends TestCase
{
use IntegrationTestTrait;
public $fixtures = [
'app.Customers',
'app.Orders'
];
public function testIndex()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testView()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testAdd()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testEdit()
{
$this->markTestIncomplete('Not implemented yet.');
}
public function testDelete()
{
$this->markTestIncomplete('Not implemented yet.');
}
}
Because I'm not using tests, can I (safely) avoid the composer test step?
By the way, on the hosting server the PHP version is 5.6 while in the pipeline's image is specified version 7. Might this lead to a problem?

Related

codeception laravel7 Failed to resolve cyclic dependencies for class 'Tests\Api\ApiTester'

I am in the middle of converting my lumen app to laravel7 and while working on tests.. I am facing an issue when running the API tests.
I have a test file named AbcCest, and when i try to run it; I keep getting the error:
Failed to inject dependencies in instance of 'Tests\Api\AbcCest'. Failed to resolve cyclic dependencies for class 'Tests\Api\ApiTester'
here is my api.suite.yml
class_name: ApiTester
modules:
enabled:
- Helper\Api
- Asserts
- Laravel5:
environment_file: .env.testing
and here is my AbcCest file
<?php
namespace Tests\Api;
class CancellationCest
{
public function _before(ApiTester $I)
{
$I->doSomething();
}
public function _after(ApiTester $I)
{
}
public function tryToAbc(\ApiTester $I)
{/*do things*/}

SQLite error opening Symfony app on Heroku

Error itself:
2021-07-20T23:43:33.993462+00:00 app[web.1]: [20-Jul-2021 23:43:33 UTC] [critical] Uncaught PHP Exception Symfony\Component\ErrorHandler\Error\ClassNotFoundError: "Attempted to load class "SQLite3Cache" from namespace "Doctrine\Common\Cache".
2021-07-20T23:43:33.993688+00:00 app[web.1]: Did you forget a "use" statement for another namespace?" at /app/src/Utils/FilesCache.php line 23
The file contents of "FilesCache.php" are similar to what's provided in Symfony's documentation here with a few additions.
<?php
namespace App\Utils;
use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Doctrine\Common\Cache\CacheProvider;
use Doctrine\Common\Cache\SQLite3Cache;
use Symfony\Component\Cache\Adapter\DoctrineAdapter;
class FilesCache implements CacheInterface
{
public $cache;
public function __construct()
{
//this is error line 23
$provider = new SQLite3Cache(new \SQLite3(__DIR__ . '/cache/data.db'), 'TableName');
$this->cache = new TagAwareAdapter(
new DoctrineAdapter(
$provider,
$namespace = '',
$defaultLifetime = 0
)
);
}
}
I've added both "pdo_sqlite" and "sqlite3" extensions to "composer.json".
Composer update runs without issue.
I'm committing both the "composer.json" and "composer.lock" before pushing the local project repo to Heroku, which runs without issue as well and shows that both extensions are added.
remote: -----> Installing platform packages...
remote: - php (8.0.8)
remote: - ext-intl (bundled with php)
remote: - ext-pdo_sqlite (bundled with php)
remote: - ext-sqlite3 (bundled with php)
remote: - composer (2.1.3)
remote: - apache (2.4.48)
remote: - nginx (1.20.1)
I know that SQLite isn't the proper choice for a production database, I'm following a course and I'd like to continue using what's provided from it.
Thank you in advance for any help!
As mentioned in the comments, the problem was the deprecation of doctrine/cache. I switched to a PDOAdapter and this fixed the issue.
<?php
namespace App\Utils;
use App\Utils\Interfaces\CacheInterface;
use Symfony\Component\Cache\Adapter\TagAwareAdapter;
use Symfony\Component\Cache\Adapter\PdoAdapter;
use Doctrine\DBAL\Driver\Connection;
class FilesCache implements CacheInterface
{
public $cache;
public function __construct()
{
$connection = \Doctrine\DBAL\DriverManager::getConnection([
'url' => 'sqlite:////%kernel.project_dir%/var/cache/data.db'
]);
$this->cache = new TagAwareAdapter(
new PdoAdapter(
$connection,
$namespace = '',
$defaultLifetime = 0
)
);
}
}

Get Laravel Dusk to Run Properly on Ubuntu 16 wt Laravel 5.5

I've been trying to integrate Laravel Dusk into my testing scheme for a week and can't get any test to actually deliver expected results. Here's the situation:
I'm running Laravel 55 on Homestead (per Project install) with php 7.1.*
I installed Dusk following the installation steps in the docs.
Out of the box the tests didn't work
I added the steps found in this article on "Laravel Dusk on Homestead" and the gist found here in "setup-headless-selenium-xvfb.sh" this to my provisioning file. This removed a lot of the exceptions I was getting.
I also added all my existing environment vars to the php node of my phpunit.dusk.xml file exactly as they were done so in the already successfully running phpunit tests from phpunit.xml
However now when I run the tests I just can't get the expected output. This is what I am doing. I add an input field in my home page ('/') view file as such: <input id="dusk-test" value="1234">
I run this test which is a mod of the original example test and is the only test:
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
class ExampleTest extends DuskTestCase
{
public function testBasicExample()
{
$this->browse(function (Browser $browser)
{
$browser->visit('/')->refresh()
->assertValue('#dusk-test', '1234')
;
});
}
}
...by running php artisan dusk and this is my output EVERY time
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.
E 1
/ 1 (100%)
Time: 1.07 seconds, Memory: 12.00MB
There was 1 error:
1) Tests\Browser\ExampleTest::testBasicExample
Facebook\WebDriver\Exception\NoSuchElementException: no such element:
Unable to locate element: {"method":"id","selector":"dusk-test"}
(Session info: headless chrome=62.0.3202.62)
(Driver info: chromedriver=2.32.498513 (2c63aa53b2c658de596ed550eb5267ec5967b351),platform=Linux 4.4.0-92-generic x86_64)
/home/vagrant/landing/vendor/facebook/webdriver/lib/Exception/WebDriverException.php:102 /home/vagrant/landing/vendor/facebook/webdriver/lib/Remote/HttpCommandExecutor.php:320
/home/vagrant/landing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:535
/home/vagrant/landing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:175
/home/vagrant/landing/vendor/laravel/dusk/src/ElementResolver.php:281
/home/vagrant/landing/vendor/laravel/dusk/src/ElementResolver.php:327
/home/vagrant/landing/vendor/laravel/dusk/src/Concerns/MakesAssertions.php:632
/home/vagrant/landing/tests/Browser/ExampleTest.php:22
/home/vagrant/landing/vendor/laravel/dusk/src/TestCase.php:92
/home/vagrant/landing/tests/Browser/ExampleTest.php:24
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
To make this even more confusing, this is my output when I dump from the test. Here's how I dump
<?php
namespace Tests\Browser;
use Tests\DuskTestCase;
use Laravel\Dusk\Browser;
class ExampleTest extends DuskTestCase
{
/**
* A basic browser test example.
*
* #return void
*/
public function testBasicExample()
{
$this->browse(function (Browser $browser)
{
$browser->visit('/')
->dump()
;
});
}
}
and my output after running php artisan dusk again is
PHPUnit 6.4.3 by Sebastian Bergmann and contributors.
"<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body></body></html>"
Which is absolutely NOT my homepage. I also dumped the $url value from vendor/laravel/dusk/src/Browser.php and got my projects correct APP_URL.
I'm at a loss. Dusk is being sent the right location and the page definitely has the input and value. But, I can't get Dusk to give the expected output which would be that 12345 was retrieved from the element.
All help appreciated.
maybe what i'm saying is wrong ... but Laravel dusk seems to need dusk instead of id: like dusk="dusk-test". also call it after :
$browser->visit('/')>refresh()
->assertValue('#dusk-test', '1234') and it should be like the doc.
On Github someone solved his problem by replacing https:// with http://
in the .env file.

Easy Deployer Bundle fails on symlinking parameters.yml

I am trying to use easy-deploy-bundle to deploy a symfony project cannot deploy any symfony project, even to my local machine. The symlinking for the parameters.yml file from the shared directory always fails with the error below.
I have cloned the symfony-demo project, this is a symfony 3.3.10, the parameters.yml file is empty but present in the shared/app/config dir.
Error:
[Symfony\Component\Process\Exception\ProcessFailedException]
The command "(export SYMFONY_ENV=prod; cd /home/patrick/code/testedb-deploy/releases/20171015162057 && ln -nfs /home/patrick/code/testedb-deploy/shared/app/config/parameters.yml /home/patrick/code/testedb-deploy/releases/20171015162057/app/config/parameters.yml)" f
ailed.
Exit Code: 1(General error)
Working directory: /home/patrick/code/testedb
Output:
================
Error Output:
================
ln: failed to create symbolic link '/home/patrick/code/testedb-deploy/releases/20171015162057/app/config/parameters.yml': No such file or directory
This is my deploy file:
<?php
use EasyCorp\Bundle\EasyDeployBundle\Deployer\DefaultDeployer;
return new class extends DefaultDeployer
{
public function configure()
{
return $this->getConfigBuilder()
->server('localhost')
->deployDir('/home/patrick/code/testedb-deploy')
->repositoryUrl('git#github.com:superpatty/symfony-demo.git')
->symfonyEnvironment('prod')
->resetOpCacheFor('https://demo.symfony.com')
;
}
public function beforeStartingDeploy()
{
$this->log('Checking that the repository is in a clean state.');
$this->log('Running tests, linters and checkers.');
$this->runLocal('./bin/console security:check --env=dev');
$this->runLocal('./bin/console lint:twig app/Resources/ --no-debug');
$this->runLocal('./bin/console lint:yaml app/ --no-debug');
$this->runLocal('./bin/console lint:xliff app/Resources/ --no-debug');
$this->runLocal('./vendor/bin/simple-phpunit');
}
public function beforeFinishingDeploy()
{
}
};
Has anyone else come across this issue and how to get around it?

Symfony init:acl command missing

I would like to use Symfony's ACL system but I am unable to initialize the database. I followed the steps here How to Use Access Control List (ACL's), but when I run the console command I get There are no commands defined in the "init" namespace.
I have the SecurityBundle defined in my AppKernel new Symfony\Bundle\SecurityBundle\SecurityBundle(). And here is my security.yml
# security.yml
security:
acl:
connection: default
I'm not quite understanding what I'm missing. I do understand though that it's likely a configuration issue. Looking at the Command in symfony's library I see
<?php
class InitAclCommand extends ContainerAwareCommand
{
/**
* {#inheritdoc}
*/
public function isEnabled()
{
if (!$this->getContainer()->has('security.acl.dbal.connection')) {
return false;
}
return parent::isEnabled();
}
//...
}
My guess is isEnabled() is returning false, but I'm not sure what or where I set the configuration for this.
I am using Symfony 3.1.9 and PHP7.0
Thanks
check you have the following package installed:
composer require symfony/security-acl
Try these commands:
composer require symfony/security-acl
Then:
composer update
Then run:
php bin/console init:acl
That should work

Categories