disable output from symfony2 command - doctrine-orm

I'm writing some unit tests and need to call some commands in the unit test in order to create a test database. However, when I call the command it's dumping the notices to the screen. Is there a way to shut this off? I've tried to execute --quiet, but it doesn't suppress the notices.
$this->runConsole("doctrine:mongodb:schema:create", array("-q"=> null,"--env" => "test"));
....
protected function runConsole($command, Array $options = array())
{
$options = array_merge($options, array('command' => $command));
return $this->_application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
}
the notices i'm getting:
[2013-02-07 16:24:43] doctrine.INFO: MongoDB query: {"deleteIndexes":true,"db":"xxxxxx","collection":"xxxxxx} [] []
[2013-02-07 16:24:43] doctrine.INFO: MongoDB query: {"deleteIndexes":true,"db":"xxxxxx","collection":"xxxxxx"} [] []
[2013-02-07 16:24:43] doctrine.INFO: MongoDB query: {"deleteIndexes":true,"db":"xxxxxx","collection":"xxxxxx"} [] []

Use CommandTester to test your command. You can read more about it here:
http://symfony.com/doc/current/components/console/introduction.html#testing-commands

I added a config_test.yml in the app/config directory and added these lines (which are copied from my config_dev.yml):
monolog:
handlers:
main:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
firephp:
type: firephp
level: info

Related

actix web test doesn't seem to be routing requests as expected

I recently updated to actix web 4, I had some tests that used the actix-web test module that stopped working as expected in the process. I'm sure it's something simple but I'm having trouble figuring out what changed. Here is a minimal example of the issue:
use actix_web::{test, web, App, HttpResponse, HttpRequest};
#[actix_rt::test]
async fn says_hello() {
let req = test::TestRequest::get().uri("/index.html").to_request();
let mut server =
test::init_service(App::new().service(web::scope("/").route("index.html", web::get().to(|_req: HttpRequest| async {
println!("Hello?");
HttpResponse::Ok()
})))).await;
let _resp = test::call_and_read_body(&mut server, req).await;
}
running this test I would expect to see "Hello?" output to my console, however, the request handler function I have defined at "/index.html" doesn't seem to be called and I receive no output.
To be clear, the tests are more complicated and have assertions etc, this is just a working example of the main issue I am trying to resolve
actix-web = { version = "4.1.0", default-features = false }
note:
if I change all paths to the root path it will call the handler, I.E.
let req = test::TestRequest::get().uri("/").to_request();
let mut server =
test::init_service(App::new().service(web::scope("/").route("/", web::get().to(|_req: HttpRequest| async {
println!("Hello?");
HttpResponse::Ok()
})))).await;
let _resp = test::call_and_read_body(&mut server, req).await;
// prints "Hello?" to the console
However no other route combination I have tried calls the request handler.
Rust tests capture the output and only output them for failed tests.
If you want to show output on all tests you have to tell them to do so with either testbinary --nocapture or cargo test -- --nocapture.
I was able to make things work by changing the path in the scope to an empty string
let req = test::TestRequest::get().uri("/index.html").to_request();
let mut server =
test::init_service(App::new().service(web::scope("").route("index.html", web::get().to(|_req: HttpRequest| async {
println!("Hello?");
HttpResponse::Ok()
})))).await;
let _resp = test::call_and_read_body(&mut server, req).await;
// prints "Hello?"

How to specify test tags correctly in dart_test.yaml?

I have a dart project that has several tests, when I try to run an isolated test I get this warning:
Warning: A tag was used that wasn't specified in dart_test.yaml.
"tagName" was used in the suite itself
how should i declare these tags correctly in dart_test.yaml?
Steps
Create a file dart_test.yaml at the root of your project
Add your tags one after another under a tags field
Add tags to your test or testWidget declaration
Run your tests with the -t flag followed by the wanted tag
Sample
Let's say I want to add the following tags: golden, atom, molecule, organism, mobile, desktop. My dart_test.yaml will look like this:
tags:
golden:
atom:
molecule:
organism:
mobile:
desktop:
And everything should be okay you can write your test:
void main() {
testWidgets(
'this is a test',
(tester) async {
// ...
},
tags: ['atom', 'mobile'],
);
}
You can run it with the following command:
$ flutter test -t mobile
source

JenkinsPipelineUnit helper can intercept text param call but not string param call

How can I get JenkinsPipelineUnit to intercept both text() and string() param calls? I have code that triggers a build with a few params. I want to write a nice unit test to check that it does what it should. However, the string() calls are not intercepted so I cannot test them. I can test the text() call.
Yes, it is possible to write unit tests for Jenkins pipeline code vs testing via jenkins production jobs. This project + shared libraries makes jenkins into a much better tool.
Any ideas on how I could do this? I looked in the JenkinsPipelineUnit project but didn't find an example that fit and couldn't figure out where to look in the runtime objects.
I do see that the project's BasePipelineTest.groovy links string to its stringInterceptor which seems to just eat it the string. Maybe, I can unregister theirs...
Example
def triggeringParams = [:]
....
for (def param in ['text', 'string']) {
helper.registerAllowedMethod(param, [LinkedHashMap],
{ LinkedHashMap data ->
triggeringParams << data
}
)
}
thisScript = helper.loadScript('''
package resources
return this''')
def params = []
params << thisScript.text(name: 'MULTILINE_PARAM', value: '\nline1\nline2')
params << thisScript.string(name: 'STRING_PARAM', value: 'a string')
thisScript.build(job: 'myJob', parameters: params)
println triggeringParams
Results
[
[name:JOB_PROPERTIES, value:
line1
line2]
]
Wrong type was the problem. The project's BasePipelineTest.groovy links string to its stringInterceptor which seems to just eat it the string and uses register Map not LinkedHashMap. So, the first is found before mine and boom, the string doesn't show in my collector.
If I modify my code to use the more generic map it works
void addParameterHelpers() {
for (def param in ['text', 'string']) {
helper.registerAllowedMethod(param, [Map],
{ LinkedHashMap data ->
triggeringParams << data
}
)
}
}

How to get Gradle combined test report?

I have multiple test suites configured (as shown below) in my gradle build
task group1(type: Test) {
useTestNG() {
includeGroups 'group1'
}
// ... some excluded tests
ext.useDefaultListeners = true
ext.workingDirectory = 'build/'
// ... some system properties required by this test
}
task group2(type: Test, dependsOn: group1) {
useTestNG() {
includeGroups 'group2'
}
// ... some excluded tests
ext.useDefaultListeners = true
ext.workingDirectory = 'build/'
// ... some system properties required by this test
}
test.dependsOn group2
When I run the gradle clean build --debug, I could see after every test task (group1, group2 etc), gradle deletes the test report and regenerates it. Hence, after the build is done, whatever report I get does not have any information. All blank!
How can I get a combined report?
Thanks,
NN
You should use a separate task of type TestReport
Check out section '23.12.7. Test reporting' in the user guide

How to enable Doctrine query logging in Symfony 1.4 unit tests

I am unit testing a model class and I would like all Doctrine queries to be logged.
My settings.yml for the test environment contains
logging_enabled: true
and my script
$configuration = ProjectConfiguration::getApplicationConfiguration( 'frontend', 'test', true);
new sfDatabaseManager( $configuration ) ;
Still, I don't see any log in any log file.
So, I found a workaround by using an event listener on the Doctrine profiler.
$profiler = new Doctrine_Connection_Profiler();
$conn = Doctrine_Manager::connection();
$conn->setListener($profiler);
/* tests go here */
foreach ($profiler as $event) {
echo $event->getQuery() . "\n";
}
But the same query is printed out several times for some reason (I am sure it is executed only once). Plus it is not so convenient to have the query logs dissociated from the rest of the log messages.