Jenkins: phpunit with namespaces in Yii-Framework - yii

I'm new to jenkins. I try to use the ci like on this website. If I build my project I Get the following consol output error
phpunit:
[exec] PHPUnit 3.7.28 by Sebastian Bergmann.
[exec]
[exec] Cannot open file "/var/www/repo/project/protected/tests/bootstrap.php".
[exec]
BUILD FAILED
/var/www/repo/build.xml:117: exec returned: 1
My build.xml
<target name="phpunit" description="Run unit tests with PHPUnit">
<exec executable="phpunit" failonerror="true">
<arg line="--log-junit ${basedir}/build/logs/phpunit.xml /var/www/repo/project/protected/" />
</exec>
</target>
My Project structure is like this:
-repo
-project
-protected
-components
-config
- ....
- tests
- unit
- bootstrap.php
- ReflectionTest.php
-build
-....
-build.xml
-phpunit.xml.dist
I'm using the Yii-Framework with namespaces. If I execute the phpunit command from the tests directory it works quite fine. But if I execute it somewhere else I get an error like this:
PHP Fatal error: Class 'application\tests\ReflectionTest' not found in /var/www/repo/project/protected/tests/unit/account/manager/ManagerTest.php on line 13
Here my test:
<?php
namespace application\tests\unit\account\manager;
use application\modules\account\manager\Manager;
use application\models;
use Yii;
use application\tests\ReflectionTest;
/**
* This class test the protected and public methods of SignupManager
*/
class ManagerTest extends ReflectionTest {
And here my phpunit.xml.dist
<phpunit bootstrap="project/protected/tests/bootstrap.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">
<selenium>
<browser name="Internet Explorer" browser="*iexplore" />
<browser name="Firefox" browser="*firefox" />
</selenium>
<testsuites>
<testsuite name="Project Test Suite">
<directory>project/protected/tests/*</directory>
</testsuite>
</testsuites>
</phpunit>
Where is my error?

I refer to my bootstrap file with the relative path from the location of the phpunit.xml file. Like this:
<phpunit bootstrap="bootstrap.php"
colors="false"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
stopOnFailure="false">

I created a sample project for Yii on github. There you can see how the settings should be for phpunit to work correctly. Check out https://github.com/perlmonkey/yii-sample-project
Also, you must take care that all relevant PHPUnit modules are available for testing. That's why I created an automated script to take care of configuring Jenkins for me: https://github.com/perlmonkey/php-ci

Related

How to use MicroProfile ConfigProperty injection from a microprofile-config.properties file in Open Liberty test using ShrinkWrap + Arquillian?

Problem
I added a microprofile-config.properties file to the Liberty "Testing microservices with the Arquillian managed container" guide sample, but my microprofile-config.properties isn't picked up by my test.
Symptom
> Exception : io.smallrye.config.inject.ConfigException: SRCFG02000:
> Failed to Inject #ConfigProperty for key serviceName into
> io.openliberty.guides.system.AppConfig.serviceName since the config
> property could not be found in any config source at
> io.smallrye.config.inject.ConfigExtension.validate(ConfigExtension.java:183)
> at
> io.openliberty.microprofile.config.internal.extension.OLSmallRyeConfigExtension.validate(OLSmallRyeConfigExtension.java:65)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> ...
Starting point
git clone https://github.com/openliberty/guide-arquillian-managed.git; cd finish
microprofile-config.properties
Path: src/main/resources/META-INF/microprofile-config.properties
serviceName=myService
Bean to inject into: AppConfig.java
#ApplicationScoped
public class AppConfig {
#Inject #ConfigProperty(name="serviceName")
private String serviceName;
...
}
Liberty server config (server.xml)
<featureManager>
<feature>restfulWS-3.0</feature>
<feature>jsonb-2.0</feature>
<feature>jsonp-2.0</feature>
<feature>cdi-3.0</feature>
<feature>mpConfig-3.0</feature>
<!--Enable the following features to run tests with Arquillian managed container-->
<feature>localConnector-1.0</feature>
<feature>servlet-5.0</feature>
</featureManager>
You need to specifically package the microprofile-config.properties file in the ShrinkWrap package like:
.addAsManifestResource(new File("src/main/resources/META-INF", "microprofile-config.properties"))
More completely in the context of this sample it would look like:
WebArchive archive = ShrinkWrap.create(WebArchive.class, WARNAME)
.addAsManifestResource(new File("src/main/resources/META-INF", "microprofile-config.properties"))
.addPackages(true, "io.openliberty.guides.system");
Explanation:
Since the sample uses ShrinkWrap to package the application test deployment, the microprofile-config.properties must be programmatically added to the ShrinkWrap deployment. It doesn't become part of the package by virtue of being in src/main/resources (like it becomes part of a standard Maven WAR package built by the maven-war-plugin).

GherkinScenarioFactory not execute any test case

I use cucumber testNG for my project and and already added some configuration based on Configuring BDD for execution and QAF Cucumber but when i run it, GherkinScenarioFactory not run any test.
[main] ERROR com.qmetry.qaf.automation.util.PropertyUtil - resources\application.properties (The system cannot find the path specified)
[main] INFO com.qmetry.qaf.automation.core.ConfigurationManager - ISFW build info: {qaf-Type=core, qaf-Revision=15, qaf-Version=2.1, qaf-Build-Time=20-N
ov-2019 22:28:06}
[main] ERROR com.qmetry.qaf.automation.core.ConfigurationManager - D:\Automation\resources not exist!
include groups []
exclude groups: [] Scanarios location: resources/features
[main] INFO com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory - scenario.file.loc[Ljava.lang.String;#400cff1a
[main] INFO com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory - total test found: 0
I've added the dependency qaf and also qaf-cucumber with version 2.1.15. I've also added the #QAFTestStepProvider annotation in the step file. Here's my testng.xml file :
<suite name="MyTest">
<test name="ComparationTest" >
<parameter name="step.provider.pkg" value="com.example.steps" />
<parameter name="scenario.file.loc" value="resources/features" />
<classes>
<class name="com.qmetry.qaf.automation.step.client.gherkin.GherkinScenarioFactory" />
</classes>
</test>
in the feature file I added : Examples: {'datafile': 'resources/data/data.xls'}
and last in cucumber runner I added plugin "com.qmetry.qaf.automation.cucumber.QAFCucumberPlugin"
I'm still learing, can somebody tell me what did i miss?
It looks that you are pointing to wrong location for resources and feature file/directory. You need to provide relative path to project root directory for resources and scenarios directory. If you observe the log also complains that fie/folder not exist.
[main] ERROR com.qmetry.qaf.automation.util.PropertyUtil - resources\application.properties (The system cannot find the path specified)
[main] INFO com.qmetry.qaf.automation.core.ConfigurationManager - ISFW build info: {qaf-Type=core, qaf-Revision=15, qaf-Version=2.1, qaf-Build-Time=20-N
ov-2019 22:28:06}
[main] ERROR com.qmetry.qaf.automation.core.ConfigurationManager - D:\Automation\resources not exist!
Make sure that you have resources directory under project root.
Regarding feature files, according to your current configuration
scenario.file.loc is resources/features. In that case make sure that <project-root>/resources/features is exist. For example your project root is D:/Automation then resources/features points to D:/Automation//resources/features
If not then provide correct relative path to project root.
For example resources/features expects <project-root>/resources/features if it is not there provide correct location.
Same is applied for other resources including properties file and test data files.
For application.properties it is expected under <project_root>\resources\application.properties if it is not there you can provide location by using system property application.properties=<relateive_path_to_project> or alternately place under default location <project_root>\resources.
As a side note,
instead of GherkinScenarioFactory recommended is BDD2 factory com.qmetry.qaf.automation.step.client.text.BDDTestFactory2
Latest version of qaf as of today is 3.1.0-RC1 the version you are using 2.1.15 is quite old.

Build Failed directory does not exist

I am new to Ant and dynamic web project. I created a build.xml and copied it from here Tomcat example. I changed all the necessary directories.
But I still get an error.
This is the error message I get:
Buildfile: /Users/{myusername}/eclipse-workspace/JSF/build.xml
prepare:
compile:
[javac] Compiling 5 source files to /Users/{myusername}/eclipse-workspace/JSF/build/WEB-INF/classes
BUILD FAILED
/Users/{myusername}/eclipse-workspace/JSF/build.xml:67: /Users/{myusername}/eclipse-workspace/JSF/usr/local/Tomcat/bin does not exist.
Total time: 649 milliseconds
And this is the line where the error occurs
<javac includeantruntime="false" srcdir="${src.home}" destdir="${build.home}/WEB-INF/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
but i don't get why
Can you help me?

BuildException when executing Ant task

I have installed Apache Ant and set the correctly the Path, CLASS_PATH and ANT_PATH variables. When I run a jar task in a command line within my project folder where the build.xml file is, I get the following error:
BUILD FAILED
C:\Documents and Settings\TonyS\My Documents\My Workspace\code\build.xml: 32:
The following error occurred while executing this line:
jar:file:/C:/Documents%20and%20Settings/TonyS/My%20Documents/Ant/apache-ant-1.8.1/lib/ant.jar!org/apache/tools/ant/antlib.xml:37: Could not create task or type: componentdef.
Ant could not find the task or a class this task relies upon.
I had this error and found it was caused by having an older version of ant.jar in the classpath.
One possibility is you may have another version of ant installed on your system and your PATH pointing to it.
Check what is ANT_HOME set to.
Run ant -version and see if it shows up 1.8.1
Add the following config in ~/.bashrc
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
Don't forget source ~/.bashrc
Hope useful for you!
you have duplicate ant in your environment.
My case was:
I am using 1.9.7 ant, but ant -version gave me 1.7.1
I installed weblogic and it has 1.7.1 ant, after rename MW_HOME, the issue was gone.
I found this while I was using 1.7.1 to test junit. it shows a warning.
junit:
[junit] WARNING: multiple versions of ant detected in path for junit
[junit] jar:file:/D:/wls12120/oracle_common/modules/org.apache.ant_1.7.1/lib/ant.jar!/org/apache/tools/ant/
Project.class
[junit] and jar:file:/D:/apache-ant-1.7.1/lib/ant.jar!/org/apache/tools/ant/Project.class
[junit] Running HelloWorldTest

openJPA on Java SE

I try to develop JPA project on ibm RAD. And i can run it on Webpshere successfully,
but the problem is my machine is quite old. So deploying in Java EE container isn't
reasonable.And i want to run it on JSE.But it gives following error:
94 test INFO [main] openjpa.Runtime - Starting OpenJPA 1.2.1-SNAPSHOT
235 test INFO [main] openjpa.jdbc.JDBC - Using dictionary class "com.ibm.ws.persistence.jdbc.sql.DB2Dictionary".
1797 test WARN [main] openjpa.Enhance - This configuration disallows runtime optimization, but the following listed types were not enhanced at build time or at class load time with a javaagent: "[class Customer]".
Exception in thread "main" <openjpa-1.2.1-SNAPSHOT-r422266:686069 fatal user error> org.apache.openjpa.persistence.ArgumentException: The type "class Customer" has not been enhanced.
at org.apache.openjpa.meta.ClassMetaData.resolveMeta(ClassMetaData.java:1650)
at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1624)
at org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:717)
at org.apache.openjpa.meta.MetaDataRepository.resolveMeta(MetaDataRepository.java:616)
at org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:541)
at org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:308)
at org.apache.openjpa.kernel.BrokerImpl.newObjectId(BrokerImpl.java:1114)
at org.apache.openjpa.kernel.DelegatingBroker.newObjectId(DelegatingBroker.java:268)
at org.apache.openjpa.persistence.EntityManagerImpl.find(EntityManagerImpl.java:451)
at deneme.main(deneme.java:21)
What i'm missing?
By the my persistent.xml is:
**<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="test" transaction-type="RESOURCE_LOCAL">
<provider>
com.ibm.websphere.persistence.PersistenceProviderImpl
</provider>
<class>Customer</class>
<properties>
<property name="openjpa.ConnectionDriverName" value="com.ibm.db2.jcc.DB2Driver"/>
<property name="openjpa.ConnectionURL" value="jdbc:db2://localhost:50000/PARUD:retrieveMessagesFromServerOnGetMessage=true;"/>
<property name="openjpa.ConnectionUserName" value="db2admin"/>
<property name="openjpa.ConnectionPassword" value="xxxxx"/>
<property name="openjpa.jdbc.Schema" value="POOL"/>
</properties>
</persistence-unit>
</persistence>**
Just a pointer:
You need to enhance your classes e.g. at runtime via -javaagent:yourlib.jar
or even while compiling. You could learn more on this topic here:
"The second and recommended way get runtime enhancement is to provide a javaagent when launching the JVM that OpenJPA is going run in."
I just went through the exercise of getting OpenJPA 2.1.0 to run on Tomcat 7.0. I was simply unable to get run-time enhancement to work under Tomcat so I gave up and decided to use build-time enhancement. I am developing my code under Eclipse so I followed the instructions here:
http://openjpa.apache.org/enhancement-with-eclipse.html
Note however that the instructions on this page are for generic java projects. If you are working with Dynamic Web Projects, be sure to specify the build directory argument correctly. I used -Dbuild.dir=build/classes which is the typical location for the compiled code.
One more annoying quirk you have to live with. You must manually invoke the builder using the "Project > Build Project" menu item. When the enhancer runs, it modifies the previously built classes. Consequently, you need to hit F5 or Refresh for the project before you publish to Tomcat.