Codeception: Force PhpBrowser to use custom environment - codeception

I have a page with a text field and button. After I fill out text field and press a button my controller is connecting to an API and getting some data based on the text.
I prepared a FAKE_API for testing. Both REAL_API and FAKE_API are in the service container. The FAKE_API is being prioritized when the environment is set to test (.env.test file). The controller gets the API object via dependency injection (constructor argument).
When I am testing using PhpBrowser from Codeception, the environment of the test itself is set to test - this can be checked by var_dump($_ENV['APP_ENV']) from the test.
However, (and this is the issue), if I add var_dump($_ENV['APP_ENV']) to the controller code and run the same test, I can see that the controller actually uses the regular 'dev' environment (set in .env file). This means that the REAL API is being used instead of my FAKE_API.
How can I force PhpBrowser tests to use my .env.test? Is it even possible?

You can't do that.
PhpBrowser communicates to system under test via HTTP, so it can't set environment variables of the system.
Your options are:
Deploy API in test configuration
Pass environment using GET or POST parameters or headers and make your app code accept it. (this is a bad idea)

Related

How to intercept log messages from Quarkus/Camel for testing purposes?

I'm building a Java application with Quarkus/Camel which generates some logstatements here and there. I want to be able to verify if the correct logstatements are generated so I have a need to intercept the logmessages. The problem is that I have a logtemplate specified in the Quarkus application.properties file, but this template is not used when running tests. As a result, I cannot verify the correctness of the logstatements.
I have tried to copy the logtemplate to the testbranch but it is nog picked up by Quarkus. Does somebody know how I can pursuade my tests to use the proper logtemplate?

Ansible API : Custom Module

I would like to use a custom module for which I require "hostname" so that I can initiate SSH connection from the custom module and run commands. So I pass transport = "local" to the Runner object. However, I find no way to obtain "hostname" information in the custom module.
I am using Ansible 1.9.2 using Python API.
A module only has the information available that was explicitly passed to it. What you might be interested in instead is an action plugin, which by (non-exisiting) definition runs local on the control machine and has access to more (all?) data.
You can see some action plugin code here: https://github.com/ansible/ansible/tree/devel/lib/ansible/plugins/action
PS: Don't you want to upgrade to Ansible 2 before getting started writing custom modules/plugins? The API changed completely and once you upgrade you have to rewrite you module/plugin.
Okay, silly me. It's exactly the same way in the API too. You can extract hostname using {{ inventory_hostname }}.

What is proper way for fixtures while using chimp with Meteor

I'm playing with chimp testing tool. At the moment I can easily run cucumber and mocha tests. The problem is that I don't know how to add DB fixtures. I'd like to have initial data before running some tests (e.g. add test user into system).
BTW that data can be added only by authenticated user and users can be create only by admin or from server level.
Can't find any docs about this for now. Any suggestions?
If you are using Meteor, you can pass the DDP parameter on the command line --DDP=http://localhost:3000 and then use server.execute to run code on the server. This code can then setup data.
If you are not using Meteor, you can use a HTTP call using request.get('http://localhost:8080/addUser').
Through HTTP / DDP you can access the server and create a testing backdoor to setup the data you need.

How do I configure database and parameters as the app passes from dev, to test to prod?

I am trying to set up my first Cloudbees app.
Is there documentation or tutorial that shows how to
a) set variables depending on the environment. e.g. restful end point URLs have to change depending on dev, test or prod
b) initialize the database. We want to initialise the database when we do from dev to test, but not from test to prod.
Thanks
a) you should use application parameters for your DEV/TEST/PROD application to have adequate URL set as system property. parameters are tied to an application ID, so a common pattern is to deploy same binary to myapp-dev, myapp-test, myapp-prod, but change the configuration bindings.
b) use a boolean system property to disable the database migration process on production.

How to test a rest api with Zend?

I don't know how to make unit test of my rest controller. Here is my code :
public function testpostAction(){
$this->dispatch('/chain');
$this->request->setHeader('Content-Type', 'text/json')
->setMethod('POST')
->setPost(array(
'chain_name' => 'mychaintest'
));
$this->assertAction('post'); ???
}
How I make a post?
Not sure if this is what you need but, if you want to make a POST call (http) to test your REST service, you can use Zend_Http_Client:
http://framework.zend.com/manual/en/zend.http.client.html
Anyway, if this is for unit testing it will be more complicated, since you'll need your application (the current build being testet) to be live and accesible in the server. That depends on how you have configured your build environment.
There should be a staging (virtual) machine where the build is (automatically) deployed before tests are run. That machine should be visible to the machine runing the tests.
Hope this helped. Cheers!
So, basically your question is how to emulate calling PUT and DELETE in your controller tests?
Since this apparently doesn't work:
$this->request->setMethod('PUT');
You can access both these actions with plain HTTP POST by providing _method parameter.
So to call PUT:
$this->request->setMethod('POST');
$this->dispatch('articles/123?_method=put');
To call DELETE:
$this->request->setMethod('POST');
$this->dispatch('articles/123?_method=delete');
More reading on how to deal with RESTful routing here - http://framework.zend.com/manual/en/zend.controller.router.html#zend.controller.router.routes.rest