No specifications found at path for a valid feature file - php

I am setting up automated testing with behat (note: I am using behat 3). I have the following directory structure:
project/
test/
features/
web/
login.feature
bootstrap/
Web/
LoginContext.php
behat.yml
This is the initial test of the whole approach. I'm explicitly keeping it simple.
My behat.yml contains the following (that's all there is in it - everything else will come later).
default:
suites:
web:
paths: [%paths.base%/features/web]
contexts: [Web\LoginContext]
My sole feature file contains the following:
Feature: Login to MedNav
In order to use MedNav application
As a user
I need to be able to login
Scenario: Valid login credentials
Given I am on the login page
When I enter invalid credentials
And I hit log in button
Then I should see "Loading, please wait..."
And I should navigate to Emergency List page
After I executed behat --init, it created file Web\LoginContext, into which I added the stubs for the steps.
Yet, when I try to execute it, nothing happens:
$ bin/behat
No scenarios
No steps
0m0.01s (13.16Mb)
If I specify the feature to execute, it tells me that No specifications found at path(s) 'features/web/login.feature'
$ bin/behat features/web/login.feature
No scenarios
No steps
0m0.01s (13.16Mb)
[Behat\Testwork\Tester\Exception\WrongPathsException]
No specifications found at path(s) `features/web/login.feature`.
behat [-s|--suite SUITE] [-f|--format FORMAT] [-o|--out OUT] [--format-settings FORMAT-SETTINGS] [--init] [--lang LANG] [--name NAME] [--tags TAGS] [--role ROLE] [--story-syntax] [-d|--definitions DEFINITIONS] [--append-snippets] [--no-snippets] [--strict] [--order ORDER] [--rerun] [--stop-on-failure] [--dry-run] [--] [<paths>]
I've tried moving things around, removing custom directories, suites, etc. - nothing works.
How can I get behat to recognise the feature file?

The answer turned out to be much simpler.
Notice this in the behat.yml:
filters:
tags: web
Because the corresponding context didn't have this tag, the feature didn't execute. I removed the tags for now - and the feature is now run.

Please check again your paths - in your case it should be something similar to:
default:
suites:
web:
paths: [ %paths.base%/test/features/web ]
And move behat.yml file to project root directory. I think calling now bin/behat Behat know nothing about behat.yml file.
I assume that you are running bin/behat from project/ path.
This is related to: http://docs.behat.org/en/v3.0/user_guide/configuration.html#custom-autoloading

Related

Codeception into another directory

I created a custom component loaded by Composer.
Here is the structure of my code when my component is loaded.
MyProject
vendor
myComponent
AFTER that, I created the file myComponentTest.php to run an unit test with Codeception.
MyProject
tests
myComponentTest.php
vendor
myComponent
It works very well with the command :
./vendor/bin/codecept run
Alright. Nothing special about it. The Codeception test is ok ! :)
But I guess the procedure is wrong, the file myComponentTest.php should be in to the vendor/myComponent directory, am I right ?
Because, this unit test is only related to the component. For example, If I decide to remove the component, it won't remove my myComponentTet.php file, so I'll have some error when I'll run my unit tests.
BUT, if I move my MyComponentTest.php into the vendor/myComponent directory, I won't be able to run this test, because the Codeception command only execute tests from the tests directory.
So what should I do please ? I'm confused about that. Thanks.
See how testing is implemented in projects with sub-projects in Yii2 framework
codeception.yml in root project directory
include:
- common
- frontend
- backend
paths:
log: console/runtime/logs
settings:
colors: true
Where common|frontend|backend directory with codeception.yml files
I hope this helps.

Uncaught Exception: Unable to locate Mix file

I am trying to run a laravel app in my local system. I have followed the https://gist.github.com/hootlex/da59b91c628a6688ceb1 link. I run the command php artisan serve command, and when I browse it, then produces the error
PHP Fatal error: Uncaught Exception: Unable to locate Mix file: /css/vendor.css. Please check your webpack.mix.js output paths and try again. in /var/www/html/laravel-app/app/helpers.php:439
In the specified line of helpers.php, it has
if (! isset($manifest[$path])) {
throw new Exception(
"Unable to locate Mix file: {$path}. Please check your ".
'webpack.mix.js output paths and try again.'
);
}
public/mix-manifest.json
{
"/mix.js": "/mix.js"
}
I couldn't sort it out. Please help. Thanks
The blade file you're loading obviously has mix('/css/vendor.css') call. You either comment out this line(s) or install npm then build your assets.
Your manifest file doesn't have /css/vendor.css but if you check your blade files (views) you'll see you are calling mix('/css/vendor.css'). So if you find and comment out this line(s) your problem will be solved.
Ideally, mix() is used for loading assets that were built by webpack. It will then take care of the versioning string for you. How mix can be used is detailed in the documentation. I will refrain myself from discussing that here.
You've built your assets by running npm run dev or similar commands. And then the manifest file doesn't contain those assets mapping. And your public directory doesn't have those assets as well. Then it's safe to assume that you can remove those mix calls from your blade (views) files.
If you have the assets built in your public directory then you can load those assets by assets function.
Lastly, you should know your assets first, before loading them to your site. I get the notion that you don't have any clue where those assets came from, so you shouldn't load them in the first place.
This happened with me and after spending quite some time and effort, I did manage to figure out what was happening and how to fix it.
Here's what happens:
You update your webpack.mix.js file with the destination where you wish to publish your compiled JS and CSS files respectively.
mix.js('resources/js/app.js', 'public/js').vue();
Mix compiles and stores the hence generated CSS and JS files within their respective destination folders when you run npm run dev or npm run watch.
laravel-app (Your laravel app root folder)
\public
\css
\app.css
\js
\app.js
When you open the application in your browser with, say Valet, Laravel spits out the following error message:
Unable to locate Mix file: /js/app.js
(or)
Unable to locate Mix file: /css/app.css
Something worth noting on the Uncaught Exception screen though, is that Laravel by default attempts to look for the files at localhost:8080. Implied that Laravel is looking for the files respectively at:
localhost:8080\css\app.css
(and)
localhost:8080\js\app.js
Hence, if your hostname or port is anything other than localhost:8080, Laravel would not be able to find your files. For example, if you're using Valet, your default URL would become laravel-app.test where laravel-app is the name of your app's root folder.
But, there's a way to fix this. And it comes directly out to Laravel's documentation.
Solution (TL;DR)
In order to use a custom mix base URL, you would require to update your config\app.php file to add the following configuration value for setting the mix URL:
'mix_url' => env('MIX_ASSET_URL', 'localhost'),
With your mix_url config option set in your app.php file, you should now be able to manipulate it by adding the MIX_ASSET_URL key in your .env file and setting it to blank, so that it points to \public\js\app.js and \public\css\app.css respectively, within your project directory.
MIX_ASSET_URL=""
That solved it for me. Hope it does it for your too. Lemme know how it goes. Cheers!
Try running npm install and after that build the assets, either npm run dev or npm run watch , depends on what you are using.
In my case,
laravel 9
I should have changed the mix-manifest.json file
"/js/application.js": "/js/application.js",
"/js/admin.js": "/js/admin.js",
"/css/application.css": "/css/application.css",
"/css/admin.css":"/css/admin.css"
Delete package-lock.json.
Delete folder 'node_modules' and run 'npm install' to reinstall all modules.
Then run 'npm run watch' or 'npm run production'.
That helps me to fix that problem.
check the package.json file for the command to build the scripts and styles, normally you will have by default: npm run dev. Might happen that you will need to run:
npm rebuild node-sass
npm run dev or npm run watch
I changed my webpack.mix.js files and made these changes there and worked. Only define the specific path to public/js/app.js in webpack.mix.js
mix.js(
[
"resources/assets/js/jquery.js",
"resources/assets/js/popper.js",
"resources/js/app.js",
],
"public/js/app.js"
)
.autoload({
jquery: ["jquery", "jQuery", "$", "window.jQuery"],
Popper: ["popper", "Popper", "popper.js"],
popper: ["Popper", "popper.js"],
})
.vue()
.postCss("resources/css/app.css", "public/css", [])
.sass("resources/sass/app.scss", "public/css")
.disableNotifications(); // to disable notifications of building app;
In My case, I change
'debug' => false, to true
in the file app.config under config folder in my project to see log in my browser. Then when I run my project got error above like you. then I change to
'debug' => false again. It works.

How to copy images to web folder with assetic

I can't believe that I'm not able to google this...
So, I have a symfony2 application, and I installed jQuery UI with Composer. That means i have project structure like this:
/app/
/src/
/vendor/components/jqueryui/
/web/
I have assetic set up to copy js/css files from the vendor folder to web. That works fine. Config:
assetic:
assets:
javascripts:
inputs:
- %kernel.root_dir%/../vendor/components/jquery/jquery.js
- %kernel.root_dir%/../vendor/components/jqueryui/ui/jquery-ui.js
- %kernel.root_dir%/../vendor/components/jqueryui/ui/i18n/jquery.ui.datepicker-cs.js
stylesheets:
inputs:
- %kernel.root_dir%/../vendor/components/jqueryui/themes/redmond/jquery-ui.css
filters: cssrewrite
After assetic:dump i have
/web/js
/web/css
cssrewrite rewrites images/image.png to ../images/image.png. I guess that's ok, assumes a /web/images directory with said images.
Now the question is: How do I copy the images from /vendor/components/jqueryui/themes/redmond/images to /web/images?
Or is there another best practice to do that? Excuse me if it's and obvious thing, I'm a .NET guy, just trying out PHP.
My answer probably isn't spot-on because I haven't tried this with vendor files but this is what worked for me:
app/console assets:install
It copies all of your public resources to your web directory.
This answer by user1814739 helped me understand this and may provide additional information for you.
Also consider this advice from the Symfony Blog:
Although developers usually execute the command without any option, most of the time it's better to execute it with the --symlink option. This makes a symbolic link of your assets instead of actually copying their files. This means that any change in the content of the web assets will have immediate effect in the application.

Translation catalog generation with Symfony2 for main app

I used the following command to generate the catalogs of my different Bundles and it worked well.
php app/console translation:update --dump-messages --force fr ProjectBlogBundle
But how should I do to translate the view that we can find on /app/Resources/views/* ?
Thanks,
If you check the command code, it looks like it's not possible: the bundle name is required and must be provided.
However, you can check this out.
Even though you can't automatically extract/update translation segments from those views, the runtime translation should work, provided that you use the same translation domain.
Even though this question is rather dated, I figured I might add this just for anybody else stumbling across this:
It seems that the desired functionality has been added in the meantime (Symfony 2.8+).
If you run the command like this:
$ app/console translation:update --help
Usage:
translation:update [options] [--] <locale> [<bundle>]
Arguments:
locale The locale
bundle The bundle name or directory where to load the messages, defaults to app/Resources folder
It seems the bundle name has become optionale and the command will default to app/Resources
I had the same problem, and the #Jan's answer helped me. So there is an example.
cd app/
php ./console console translation:update --dump-messages --force fr .
As . is a directory (the current directory), the translator will try to load the subdirectory /Resources, so here it will try to load app/Resources/.

php unit first test symfony

I am trying to set some tests in symfony.
I am doing the first steps on that.
My question is from which folder should we write the phpunit -c app
I mean in c:/
or from the bundle
because I get the message of the not recognised internally command.
You must run it from root direcory of your application. app is just an argument which specify folder where phpunit.xml.dist places.

Categories