Permalink
Browse files

Converted Phactory to use PHP namespaces and instance objects

The structure of Phactory was causing problems with autoloaders, since
there were Phactory.php and a PhactoryMongo.php files, but each file
contained a class with the same name. In addition, the classes for
MongoDB were encapsulated in a PhactoryMongo subdirectory, but the
classes for testing SQL databases were not.

Furthermore, the use of a fully static class caused fatal errors when
attempting to run the unit tests with PHPUnit. This is because of the
static property for $_pdo. PHPUnit was attempting to serialize this
object and failing to do so. Unfortunately, efforts to set
backupStaticAttributes to false in phpunit.xml or disable it at the
class/method level failed, and I found that this could also be related
to the following bug:

sebastianbergmann/phpunit#254

After setting processIsolation="false", stopOnFailure="false", and
stopOnError="false", I was able to debug indiviual problems one-by-one
until the tests all passed, then I could turn processIsolation back on,
and the tests continued to pass.

As a result of my changes, this version of Phactory BREAKS BACKWARDS
COMPATIBILITY with all previous versions, but I think it leads to a
cleaner, easier-to-use, and easier-to-test interface.
  • Loading branch information...
1 parent d5487f6 commit d3b60eeedea955ab7b5803ec29446d19888d3849 Ben Ramsey committed May 21, 2012
Showing with 1,178 additions and 1,107 deletions.
  1. +3 −0 .gitignore
  2. +21 −0 composer.json
  3. +0 −376 lib/Inflector.php
  4. +0 −248 lib/Phactory.php
  5. +0 −3 lib/Phactory/Association/OneToOne.php
  6. +0 −27 lib/Phactory/DbUtilFactory.php
  7. +377 −45 lib/Phactory/Inflector.php
  8. +4 −2 lib/{PhactoryMongo → Phactory/Mongo}/Association.php
  9. +10 −0 lib/Phactory/Mongo/Association/EmbedsMany.php
  10. +9 −0 lib/Phactory/Mongo/Association/EmbedsOne.php
  11. +13 −11 lib/{PhactoryMongo → Phactory/Mongo}/Blueprint.php
  12. +6 −4 lib/{PhactoryMongo → Phactory/Mongo}/Collection.php
  13. +47 −0 lib/Phactory/Mongo/Inflector.php
  14. +4 −2 lib/{PhactoryMongo → Phactory/Mongo}/Logger.php
  15. +47 −52 lib/{PhactoryMongo.php → Phactory/Mongo/Phactory.php}
  16. +3 −1 lib/{PhactoryMongo → Phactory/Mongo}/Sequence.php
  17. +3 −1 lib/Phactory/{ → Sql}/Association.php
  18. +5 −3 lib/Phactory/{ → Sql}/Association/ManyToMany.php
  19. +5 −3 lib/Phactory/{ → Sql}/Association/ManyToOne.php
  20. +5 −0 lib/Phactory/Sql/Association/OneToOne.php
  21. +27 −19 lib/Phactory/{ → Sql}/Blueprint.php
  22. +7 −3 lib/Phactory/{ → Sql}/DbUtil/MysqlUtil.php
  23. +8 −4 lib/Phactory/{ → Sql}/DbUtil/SqliteUtil.php
  24. +26 −0 lib/Phactory/Sql/DbUtilFactory.php
  25. +3 −1 lib/{PhactoryMongo → Phactory/Sql}/Inflector.php
  26. +4 −2 lib/Phactory/{ → Sql}/Logger.php
  27. +242 −0 lib/Phactory/Sql/Phactory.php
  28. +11 −7 lib/Phactory/{ → Sql}/Row.php
  29. +3 −1 lib/Phactory/{ → Sql}/Sequence.php
  30. +8 −4 lib/Phactory/{ → Sql}/Table.php
  31. +0 −6 lib/PhactoryMongo/Association/EmbedsMany.php
  32. +0 −5 lib/PhactoryMongo/Association/EmbedsOne.php
  33. +40 −42 tests/{phactory_mongo/PhactoryMongoTest.php → Phactory/Mongo/PhactoryTest.php}
  34. +15 −12 ...ssociation/Phactory_Association_ManyToManyTest.php → Phactory/Sql/Association/ManyToManyTest.php}
  35. +35 −0 tests/Phactory/Sql/Association/ManyToOneTest.php
  36. +44 −0 tests/Phactory/Sql/BlueprintTest.php
  37. +10 −11 ...tory/Phactory/DbUtil/Phactory_DbUtil_SqliteUtilTest.php → Phactory/Sql/DbUtil/SqliteUtilTest.php}
  38. +8 −8 tests/{phactory/Phactory/Phactory_InflectorTest.php → Phactory/Sql/InflectorTest.php}
  39. +87 −99 tests/{phactory → Phactory/Sql}/PhactoryTest.php
  40. +15 −18 tests/{phactory/Phactory/Phactory_RowTest.php → Phactory/Sql/RowTest.php}
  41. +11 −1 tests/bootstrap.php
  42. +0 −32 tests/phactory/Phactory/Association/Phactory_Association_ManyToOneTest.php
  43. +0 −47 tests/phactory/Phactory/Phactory_BlueprintTest.php
  44. +12 −7 tests/phpunit.xml.dist
View
@@ -2,3 +2,6 @@ phpunit.xml
*.swp
*.db
*.db-journal
+reports/
+vendor/
+composer.lock
View
@@ -0,0 +1,21 @@
+{
+ "name": "Phactory",
+ "description": "A Database Factory for PHP Unit Tests",
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "require-dev": {
+ "ext-pdo": "*",
+ "ext-pdo_sqlite": "*",
+ "ext-mongo": "*"
+ },
+ "suggest": {
+ "ext-pdo": "Allows use of Phactory for testing against SQL databases",
+ "ext-pdo_mysql": "Allows use of Phactory for testing against MySQL databases",
+ "ext-pdo_sqlite": "Allows use of Phactory for testing against SQLite databases",
+ "ext-mongo": "Allows use of Phactory for testing against MongoDB databases"
+ },
+ "autoload": {
+ "psr-0": {"Phactory": "lib/"}
+ }
+}
Oops, something went wrong.

0 comments on commit d3b60ee

Please sign in to comment.