Symfony 5 custom reusable bundle installation using flex - how to test and run a private recipe server - symfony

I have created a test reusable Symfony 5 bundle and have written a Flex recipe to automatically install and configure it within any project which is private.
My problem is, I have no idea how to run and test this. I cannot find any clear complete instructions anywhere. The official documentation does not specify how this would be done and only specifies how to create the manifest.json file.
https://github.com/symfony/recipes
I found the following info which specifies uploading the recipe to a private repository on GitHub and then activating Symfony Recipe Server for the repository which I have done.
https://blog.mayflower.de/6851-symfony-4-flex-private-recipes.html
but then what?

If understood this correctly, you want to add custom domain from where recipe would be downloaded and installed. Check this project:
Github https://github.com/moay/server-for-symfony-flex
Docs https://server-for-symfony-flex.readthedocs.io/en/latest/
Eventually you get to the point where you add custom endpoint from where to download the recipe like this:
Using the server in your Symfony project is as easy
as adding the proper endpoint to your composer.json:
{
...
"symfony": {
"endpoint": "https://your.domain.com"
}
}
I apologize if this is not in the desired format of an answer.

Related

Codeception Simple Unit Test Not Work To Find My Namespaces

I'm trying a basic UnitTest with Codeception. No frameworks are used.
My working root is as:
tests |
|-unit
|-Test.php
includes|
|-general
|-Custom.php
In Custom.php
<?php
namespace Custom;
class General {
public static function check(){}
}
My test case is:
<?php
use Custom\General;
use PHPUnit\Framework\TestCase;
final class Test extends TestCase
{
public function testPushAndPop(): void
{
General::check();
}
}
I also have in my composer.json:
"autoload": {
"psr-4":{
"Custom\\":"includes/general"
}
},
When I run
php vendor/bin/codecept run unit
...
1) Test: Push and pop
Test tests/unit/Test.php:testPushAndPop
[Error] Class 'DB\General' not found
#1 /var/www/html/prj/tests/unit/Test.php:9
Codeception Simple Unit Test Not Work To Find My Namespaces
This is less about Codeception but how PHP autoloading works in general and what the configuration of autoloading in Composer is in specific:
{
"autoload": {
"psr-4":{
"Custom\\":"includes/general"
}
}
}
Even the path-segment includes/general does map on the file-system path includes/general/ (composer should have told you to add / at the end of the path-segment), the error message
[Error] Class 'DB\General' not found
#1 /var/www/html/prj/tests/unit/Test.php:9
shows that the namespace of Custom\\ in the Composer configuration is different to the namespace of the class that is not found (which is DB\\).
So even the framework you have in use (you have one and that is the testing framework) may load the composer auto-loader (highly likely), its just that the class is not found.
As #Naktibalda already highlighted in a comment, it is just a plain autoloader configuration issue.
You are right, but why? The IDE does not claim any error... (your reaction)
These are two pair of shoes.
Your IDE most likely does not rely on the autoloader and just guesses the file from the file-system.
Depending how well maintained and configured your IDE is, it perhaps should and could have highlighted you that.
On the other hand, PHP can only rely on the autoloader, in your case you delegate the autoloading to composer(1), not to your IDE.
So maybe improve on that end as well, composer is more central for your projects development than the IDE can be.
So a suggestion:
Whenever changing the composer.json file, I suggest to run composer validate --strict to check your status, then follow with a composer update.
Run this automatically before running your tests. You may not want to run composer update, then run composer install before running the test-runner if you have it as a development dependency.
Example to bind this for a single test run command within your composer.json:
{
"scripts": {
"test": [
"#composer --no-plugins --version",
"#composer validate --strict",
"#composer --no-plugins -q install --no-scripts --no-progress",
"codecept run unit"
]
}
}
you then have a single call to run all the important things in your Composer based project:
$ composer test
...
Running unit-tests is a good way to verify the autoload configuration by the way. With the composer test-script you ensure it is always up-to-date when running the test-suite, too.
You don't need an IDE for this technically, which makes it more portable and stable giving you the peace of mind for your composer based project to grow.

Instalation of Intershop 7.9 failing on missing version for demo cartridges

I'm trying to install a demo shop of Intershop version 7.9 but i'm failing to get it working. When I run "gradlew deployServer" I'm getting an error on all dependencies of the first demo shop cartridge:
Could not resolve all dependencies for configuration ':app_sf_responsive:compile'.
Could not resolve com.intershop.business:ac_ecircle:.
Required by:
nl.test.testproject:app_sf_responsive:1.0.0-LOCAL
No version for module 'com.intershop.business:ac_ecircle' in project properties and no version declared in dependency. Consider adding a version or filter property to 'C:\projects\test7.9\projects\testproject\gradle.properties'
I have followed the complete Intershop manual Setup CI Infrastructure but there is one point I don't know exactly what to do, that's with the new versioning plugin.
It is in chapter 6.2.5, any one have an idea how to configure that?
After loads of tinkering and mails back and forth with Intershop support I found a solution.
My alterations are in section 7.2.4 of the Setup CI Infrastructure of Intershop:
https://support.intershop.com/kb/index.php/Display/279D85#Cookbook-SetupCIInfrastructure-CorporateArtifactsRecipe:SetupCIBuildforCorporateArtifacts
I Made sure the corporate distribution is unique since I have more that 1 Intershop installation. Otherwise the upload to Nexus(in my case) will still fail.
In the build.gradle of the corporate distibution folder added disableSCM = true in the scm.version section. It now looks like this:
scm {
version {
type = 'threeDigits'
increment = 'MAJOR'
patternDigits = 1
disableSCM = true
initialVersion = '2.0.0'
}
}
If this is not added I got a bad request httpstatus 400 from Nexus because it tried to upload it as a snapshot while the distribution repository is a release repository.
Another problem is the distributionURL in the project/gradle/wrapper/gradle-wrapper.properties
All Nexus repository URL's are build up with < repoBaseURL > + repositories/snapshots, but the distributionURL is missing the repositories part.
After applied those changes it worked for me.

Creating a Bundle outside src/

I have created a bundle with symfony 2.3 but in this case (cause my teacher asked to me) outside src/ folder so I have ../symfony/fuentes/NameBundle instead of ../symfony/src/NameBundle. The new line appears in AppKernel and my new bundle appears on routing.yml, but when I try to launch the server
Bundle generation
Generating the bundle code: OK
Checking that the bundle is autoloaded: FAILED
Confirm automatic update of your Kernel [yes]?
Enabling the bundle inside the Kernel: OK
Confirm automatic update of the Routing [yes]?
Importing the bundle routing resource: OK
The command was not able to configure everything automatically.
You must do the following changes manually.
- Edit the composer.json file and register the bundle
namespace in the "autoload" section:
I have edit autoload and tried a lot of things (looking for here) but it appears the same error always.
C:\Users\Akenateb\Documents\UOC\AULAMENTOR\Symfony>php app/console server:run 127.0.0.1:8080
PHP Fatal error: Class 'AulaMentor\ExdosBundle\AulaMentorExdosBundle' not found in C:\Users\Akenateb\Documents\UOC\AULAMENTOR\Symfony\app\AppKernel.php on line 20
Can someone help me? I'm really stuck with it.
Thanks in advance.
First of all I want to thanks to the people who has answered. Here is what we have to do if we want to create a bundle outside 'src' folder, for example in 'fuentes' > '..Symfony/fuentes'.
If you have create with 'generate:bundle' I suggest you accept when the generator ask you if you want to create the complete structure, if you have create a bundle with generator goto step 3.
1- Make sure you have registered bundle in AppKernel and It exists there a line like this:
new YourProject\NameprojectBundle\YourProjectNameprojectBundle(),
2- Make sure you have adding a route to your app/config/routing and 'routing.yml' has you new bundle route, like this (you can add a prefix to your url, in this case fuentes):
your_project_name:
resource: "#YourProjectNameprojectBundle/Resources/config/routing.yml"
prefix: /fuentes
3- We edit 'app/autoload.php' and we add this line:
$loader->add('YourProject',realpath(__DIR__.'/../fuentes'));
Finally we can update assets doing with command line:
php app/console assets:install web
Hope it helps to someone.
Best Regards.
Do exactly as said in the comment:
Edit the composer.json file and register the bundle namespace in the "autoload" section
The src folder is automatically loaded using PSR convention. If you set classes outside of the src folder, they have to be declared as well.
In your composer.json file you can add another element in the autoload section. Here's an example that I think will work for your use case:
"autoload": {
"psr-0": {
"NameBundle\\": "fuentes/",
"": "src/"
}
},
Here's how to add simply another bundle outside your Symfony project, when we don't want to mess up with composer.json file.
The 2 first points are the same as in the Michael J.'s answer. Now to the 3rd point:
Say, we need to add a OurCompany/SomeBundle residing in the other project, which relative path is ../../OtherProject/src/OurCompany/SomeBundle to CurrentProject/app dir.
So we add this bundle to the CurrentProject application this way:
$loader->add('OurCompany\\SomeBundle', realpath(__DIR__.'/../../OtherProject/src'));
PLEASE NOTICE how the slashes and backslashes should be used (the remaining / or \ at the end doesn't matter, it's smart enough to figure it out).
And for the whole namespace to be loaded (all bundles namespaces in the other project available in CurrentProject):
$loader->add('OurCompany', realpath(__DIR__.'/../../OtherProject/src'));

Export package in OSGi Bundle

I have an OSGi Bundle and a servlet. Now I want to access the bundle from the servlet. For that purpose I use the following in the servlet:
#Resource
BundleContext context
...
ServiceReference ref = context.getServiceReference("package.MyOSGiServiceInterface");
MyOSGiServiceInterface service = context.getService(ref);
The Problem is that my servlet doesn't know MyOSGiServiceInterface 'cause that is defined in the OSGiBundle. In Eclipse I added a reference to the bundle Project in my Build Path. But at runtime it obviously can't find it.
To solve that Problem I played around with
(in bundle manifest)
Export-Package: package-of-osgi-service-interface
(in servlet manifest)
Import-Package: package-of-osgi-service-Interface
Dependencies: ...,deployment.MyBundle
But I couldn't solve it.
Whats the missing step? How can I tell JBoss to add the package containing MyOSGiServiceInterface in OSGiBundle to the class path?
Thanks for answers!
(JBoss AS 7.1.1)
--> error message <--
Eventually I solved it. I had to put the right combination of settings together to reach my goal:
Deploy the bundle per: File - Export - "Deployable plug-ins and fragments" into folder: "jboss/standalone/deployments"
Bundle-Manifest:
Bundle-SymbolicName: TestBundle
Bundle-Version: 1.0.0
Export-Package: "package-which-includes-my-service"
Servlet-Manifest:
Dependencies: org.osgi.core,org.jboss.osgi.framework,deployment.TestBundle:1.0.0
Import-Package: "package-which-includes-my-service"

How to install a Symfony 2.0 Bundle from Zip file

I tried installing the FixturesBundle as described in http://symfony.com/doc/2.0/bundles/DoctrineFixturesBundle/index.html but my proxy wont let me out.
So I went to https://github.com/doctrine/data-fixtures and download a zip from the latest commit.
I unzipped into the vendor directory and renamed it to doctrine-fixures. I edited the autoload.php and AppKernel.php files as described in the tutorial.
When I run:
php app\console doctrine:fixtures:load
I get the following message:
PHP Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesB
undle' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on
line 20
Fatal error: Class 'Symfony\Bundle\DoctrineFixturesBundle\DoctrineFixturesBundle
' not found in C:\NetbeansProjects\route_rest_service\app\AppKernel.php on line
20
Is there a way to run the installation of bundle pointing it to a zip file?
I´m running Symfony 2.0.9 on Windows 7.
Seems like the doctrine bundle has been moved outside of Symfony scope back to Doctrine.
Please, use https://github.com/doctrine/DoctrineFixturesBundle
I had the same problem and this is how i successfully solved it. I started to download this files data-fixtures and DoctrineFixturesBundle, unzipped both into /vendor/doctrine and created this folder structure:
vendor
- doctrine
- doctrine-fixtures-bundle
- Doctrine
- Bundle
- FixturesBundle
DoctrineFixturesBundle.php
..other files...
vendor
- doctrine
- data-fixtures
- lib
- test
composer.json
..other files...
Then i edited the AppKernel.php and added
public function registerBundles(){
.....
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),
.....
}
Edited the composer.json located in the root of the project and added this 2 lines:
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
Mine, now look like this:
{
"autoload": {
"psr-0": {
"": "src/",
"Doctrine\\Bundle\\FixturesBundle": "vendor/doctrine/doctrine-fixtures-bundle",
"Doctrine\\Common\\DataFixtures": "vendor/doctrine/data-fixtures/lib"
}
}
}
afterwards execute composer dump-autoload -o to recreate the classmap. All this was thanks to the users Wouter J and nifr that answered my question How to install DoctrineFixturesBundle offline
Happy coding!
Yes, it's true that Doctrine is being moved away from the Symfony namespace (see here).
So if you're using the Symfony standard distribution you download from the website (without using git), and you want to have the FixturesBundle installed manually, you have to download the doctrine-fixtures library from here, extract the zip into
YourProject/vendor/doctrine-fixtures
Download the FixturesBundle from here, and extract it in
YourProject/vendor/bundles/Doctrine/Bundle/FixturesBundle
Then you have to register the library's namespace, do it by adding
'Doctrine\\\\Common\\\\DataFixtures' => \__DIR\__.'/../vendor/doctrine-fixtures/lib',
in your autoload.php.
In addition, you'll have to register the Doctrine's namespace, because some part of your application will be using the DoctrineBundle shipped from the Symfony namespace, but the new downloaded FixturesBundle will be using the new Doctrine's namespace, so to make it work, in your autoload.php add the following line (taking care you do it before the Doctrine namespace, remember that more specific rules go first!)
'Doctrine\\\\Bundle' => \__DIR\__.'/../vendor/bundles',
So all you have to do now is to register the new bundle in your AppKernel.php writing
new Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle(),

Resources