Unit Testing with SubSonic, ActiveRecord and SqlQuery - unit-testing

I'm trying to use the built-in testing features of Subsonic 3.0.0.4 by setting my connection string to "Test". My data access routines use the SqlQuery class. When I try to run a test against the "in-memory" repository, I receive this error:
System.ArgumentException: Format of
the initialization string does not
conform to specification starting at
index 0.
When debugging, I can see that the database class, which inherits from IQuerySurface, is in test mode.
Is it possible to use the built-in testing feature in Subsonic with ActiveRecord and SQLQuery?

Is it possible to use the built-in testing feature in Subsonic with ActiveRecord and SQLQuery?
No the built-in testing only works with Linq queries

Related

CakePHP unit testing components containing db calls

I'm trying to test a component in unit tests. problem I have is with database calls. I get error saying that association is not declared in my table class. But association is there, I checked by pasting code to AppController which returns data correctly.
How can I test my component code when I use associations in my query builder.
Looks like generic tableClass is used instead of my declared table class?

Using UniqueEntity outside of Symfony stack

I have an app built on top of Silex and I'm using Doctrine as my ORM.
I have a problem where I'm trying to get a clean error for when a user tries to reuse an email, I found the validator UniqueEntity but it seems to be designed for the full stack version of Symfony.
My question is, is this true? I'm going a limb and assuming it as I haven't found anyone who successfully used it outside of Symfony.
My second question is, if I'm not able to use UniqueEntity, whats my next best option? I'm using the Symfony Validator component and would like to use something that's plugged into that to keep it all in the same block of code.
You can use UniqueEntity with Silex.
Here's the service provider package with the Doctrine ManagerRegistry implementation - saxulum/saxulum-doctrine-orm-manager-registry-provider. Also you can find the instructions how to use it with the UniqueEntity validator in README.
But you may want to implement you own UniqueEntity validator.
For example, if you want to validate DTO object (or any non-entity object), because it's not supported by Symfony's UniqueEntity validator (see issue on GitHub).

mocking database objects with Rhino mock

I am sorry if this question is already been asked. I am very new to Unit Testing and I am suppose to use Rhino for mocking.
So the problem is...I have a method to test and that method is suppose to do retrive some data based on input parameter and return as datatable.
It also do some calculation for finding out which stored procedure should be called and with which set of parameters.
I issue is that, When I call the method with mock objects....it throws an error at date from database retrival line of code as object is not set to an instanse. That is expected as their is no data retruning from database since we are mocking it.
so what could be done it that case.
Seems like it is a good time to introduce Repository Pattern.
If you introduce than, the logic to generate query to DB and the logic to read data from DB will be encapsulated in the Repository.
In this case you can mock/stub the Repository in your tests and you can unit test all the classes, which use Repository, without creation test DB at all.
The Repository mock will verify whether incoming parameters are correct.
And the Repository stub will return any test-specific data which you need for each particular test.

doctrine migrations phar, how to setup type mapping?

I want to use doctrine migrations in my non-symfony project, so I got the phar standalone from https://github.com/doctrine/migrations. I configured everything properly (db-configuration and configuration) and then when doing "migrations:status" I get the error:
[Doctrine\DBAL\DBALException]
Unknown database type enum requested,
Doctrine\DBAL\Platforms\MySqlPlatform may not support it.
Now there are many resources on how to fix this in the context of a symfony app (for instance http://wildlyinaccurate.com/doctrine-2-resolving-unknown-database-type-enum-requested) but where can I put this type mapping in this case? Should I extract the .phar, put the code in it (where?) and then re-package it? (how?)
I have tried something for Zend framework and it worked:
Open ./vendor/doctrine/dbal/lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Search for function initializeDoctrineTypeMappings()
create an entry for enum as,
'enum' => 'string'
Worked like charm !
That problem resolved in this fork
https://github.com/dyadyavasya/migrations
By default Doctrine does not map the MySQL enum type to a Doctrine type. This is because Enums contain state (their allowed values) and Doctrine types don’t.
Use fork at link and you can register MySQL ENUMs to map to Doctrine strings.
This way Doctrine always resolves ENUMs to Doctrine strings.
migrations.yml
name: Doctrine Sandbox Migrations
migrations_namespace: DoctrineMigrations
table_name: doctrine_migration_versions
migrations_directory: /path/to/migrations/classes/DoctrineMigrations
mapping_types:
enum: string
More information - https://github.com/dyadyavasya/migrations#migrationsyml
What Ocramius said:
You need to use migrations and setup the CLI on your own. Start from cloning github.com/doctrine/migrations and installing via composer. After that, customize your CLI runner to setup the connection according to your own needs.

Unit testing code which uses Umbraco v4 API

I'm trying to write a suite of integration tests, where I have custom code which uses the Umbraco API. The Umbraco database lives in a SQL Server CE 4.0 database (*.sdf file) and I've managed to get that association working fine.
My problem looks to be dependancies in the Umbraco code. For example, I would like to create a new user for my tests, so I try:
var user = User.MakeNew("developer", "developer", "mypassword", "my.email#email.com", adminUserType);
Now as you can see, I have pass a user type which is an object. I've tried two separate ways to create the user type, both of which fail due to a null object exception:
var adminUserType = UserType.GetUserType(1);
var adminUserType2 = new UserType(1);
The problem is that in each case the UserType code calls it's Cache method which uses the HttpRuntime class, which naturally is null.
My question is this: Can someone suggest a way of writing integration tests against Umbraco code? Will I have to end up using a mocking framework such as TypeMock or JustMock?
Here are some resources that may help:
http://www.aaron-powell.com/unit-testing-with-umbraco
http://stream.umbraco.org/video/726639/aaron-powell-unit-testing