Unit Testing Notes

1 view
Skip to first unread message

Ira Go

unread,
Nov 12, 2009, 1:51:44 AM11/12/09
to phpDays - php5 framework
Hello,

Decided to write some notes while it's still fresh in my mind.

# would be nice to have Days_Exception in a separate file. right now
it's in lib/Days/Engine.php.

# there is an unnecessary dependency on Days_Engine and Days_Config
(plus all that comes with it) in some view classes. It could all be
set through constructors' parameters.

# an unusual merge in the set() methods. Shouldn't it be FIFO?

That's all for now.

Anton Danilchenko

unread,
Nov 13, 2009, 7:05:28 AM11/13/09
to php...@googlegroups.com
Hi Irina!

Please, add new issues to ISSUE tracker if this a task, but or improvements.

About Days_Exception - you are right! Need create this separate file lib/Days/Exception.php
In tests include this file and exceptions work well.


# an unusual merge in the set() methods. Shouldn't it be FIFO?
Wow. I devete this parameter before reading you message. Please review change.


# there is an unnecessary dependency on Days_Engine and Days_Config
(plus all that comes with it) in some view classes. It could all be
set through constructors' parameters.

Help me - show me examples.

Thanks for you good job!

2009/11/12 Ira Go <let...@gmail.com>

Ira Go

unread,
Nov 14, 2009, 2:02:15 AM11/14/09
to phpDays - php5 framework

> About Days_Exception - you are right! Need create this separate file
> lib/Days/Exception.php
OK. That's an easy one.

> In tests include this file and exceptions work well.

Right now I have a stub for it.

> # an unusual merge in the set() methods. Shouldn't it be FIFO?
> Wow. I devete this parameter before reading you message. Please review
> change.

I'm talking about the order (First In, First Out). For example, if you
have an "A"
and you want to add a "B" to it, you would expect to get "AB", not
"BA".

> # there is an unnecessary dependency on Days_Engine and Days_Config
> (plus all that comes with it) in some view classes. It could all be
> set through constructors' parameters.
>
> Help me - show me examples.

OK.

> Thanks for you good job!

You are welcome. Really it's turned out to be fun to write unit tests.
So
thank you too.
Anton, do you have UML diagrams of the project?

Ira Go

unread,
Nov 14, 2009, 2:08:19 AM11/14/09
to phpDays - php5 framework
> # an unusual merge in the set() methods. Shouldn't it be FIFO?
> Wow. I devete this parameter before reading you message. Please review
> change.

By the way, please do not hesitate to run the tests. Moreover, to
change them!
Thanks.

Anton Danilchenko

unread,
Nov 14, 2009, 2:51:28 AM11/14/09
to php...@googlegroups.com
I not create UML diagrams for urrent project. But for previous my projects - I create UML diagrams into DIA.

Please, see on my changes in View component.

About dependency between Days_Engine and Days_Config. I read about Registry pattern and Dependency Injection metodology. Maybe in phpDays need implement this refactoring methods for improve quality of our code.

Irina, if you have - I create for you specially official email address @phpdays.org. Available only 50 addresses for main team members only. If you have it - please, tell me you expected address and I create it for you.

Regards!

2009/11/14 Ira Go <let...@gmail.com>

Ira Go

unread,
Nov 15, 2009, 2:10:41 AM11/15/09
to phpDays - php5 framework

> I not create UML diagrams for urrent project. But for previous my projects -
> I create UML diagrams into DIA.

Something to look forward to.

> Please, see on my changes in View component.

I left some comments http://code.google.com/p/phpdays/source/detail?r=285

> About dependency between Days_Engine and Days_Config. I read about Registry
> pattern and Dependency Injection metodology. Maybe in phpDays need implement
> this refactoring methods for improve quality of our code.

I'm not sure about the Registry pattern, in this case it does not
matter yet (maybe
later it will become more clear). What is important right now is how
to decouple
Days_View_* classes from Days_Engine and Days_Config. The Dependency
Injection will work well for this. It will make writing unit tests
(using mock objects)
a breeze. At first, it can be implemented using an associative array
and then just
see how it goes. I'll create a branch for this, so it wont interrupt
anybody.

> Irina, if you have - I create for you specially official email address @
> phpdays.org. Available only 50 addresses for main team members only. If you
> have it - please, tell me you expected address and I create it for you.

Thank you, Anton. If there is a limit on the number of addresses, you
better save it.
I'm barely keeping up with my email.

Thank you,
Ira

Anton Danilchenko

unread,
Nov 15, 2009, 4:24:18 AM11/15/09
to php...@googlegroups.com
I see Dependency Injection on http://h-type.com/filez/lj/articles/di/

Today we will release phpDays 1.1 beta2. Please, check system with tests. If all right - I create new archive and upload on server. Also will create tag for this relese.

I will see on you changes and reply.

2009/11/15 Ira Go <let...@gmail.com>

Anton Danilchenko

unread,
Nov 15, 2009, 4:54:29 AM11/15/09
to php...@googlegroups.com
About comments in code:

There is a problem here. If the old value is 0 (zero) or "0", it will be dismissed.

You are right. Please, add cheking for is_numeric() to condition.

The new value is inserted in front of the old one. It is quite unusual. Please give me an example of how it's used. I'm in doubt and haven't written any tests on merging yet (lucky me, the signature's changed :-)

This I have use only fot title of page.
Site name "phpDays community".
In action indexAction() in controller Forum I add this title "Forum".
In result we see this: "Forum | phpDays community".

I see on this problem, and think that need add new parameter $addBefore=false or similar. By default we set in end of string. But if set to true - we set after existing variable.

2009/11/15 Ira Go <let...@gmail.com>

Ira Go

unread,
Nov 16, 2009, 1:59:14 AM11/16/09
to phpDays - php5 framework
About the merge feature in Days_View_Interface::set().
Is it worth the trouble?
First, it is confusing, so it has to be described well in the docs and
still
people (like me, for one) can get confused.
Second, it is error-prone. The values to be merged must be strings or
be
convertible to strings. So, if even one of the values is a wrong type,
it
must be communicated to the caller. Then an intelligent decision must
be
made about what a legitimate "non empty" value is. And that decision
is out of
control of the caller.
How about dropping this feature and have a simple and clean set($key,
$value)
method? Users just can call get()/set() and merge the values whatever
way they
want it.
Well, it's just my opinion.

Anton Danilchenko

unread,
Nov 16, 2009, 6:20:39 AM11/16/09
to php...@googlegroups.com
Good. Create two separated methods: add($name, $value, $before=false) and set($name, $value).

Add() method used for add new element to existing. If element not existing - used set() method. In parameters we pass not only strings, but also numbers and arrays.

Arrays - merged. If Passed array and string - added this string to end (or start) of this array.
Strings - joinned one by one string.
Numbers - plus two values (call add(1, 2) return 3). Check numbers by function is_numeric(). If one of parameters not numeric - handle it as strings.

Thank you for tell me about this improvement!

2009/11/16 Ira Go <let...@gmail.com>

Ira Go

unread,
Nov 18, 2009, 2:41:33 AM11/18/09
to phpDays - php5 framework
I agree on the set() method. Trimming it to the bone is an
improvement.
Disagree on the add() method. It doesn't bring any value (it does not
do anything
that can't be done by get() and set()), it will only create a breeding
ground for bugs.
You are familiar with the KISS principle and Occam's Razor, right?
http://en.wikipedia.org/wiki/KISS_principle
http://ru.wikipedia.org/wiki/%D0%9F%D1%80%D0%B8%D0%BD%D1%86%D0%B8%D0%BF_KISS
http://en.wikipedia.org/wiki/Occam%27s_razor
http://ru.wikipedia.org/wiki/%D0%91%D1%80%D0%B8%D1%82%D0%B2%D0%B0_%D0%9E%D0%BA%D0%BA%D0%B0%D0%BC%D0%B0

It would be nice to have live and working examples in the set()
method's comments
or documentation. They can be included in unit tests and tested for
all the underlying
template systems.

Anton Danilchenko

unread,
Nov 22, 2009, 3:58:55 PM11/22/09
to php...@googlegroups.com
Thanks for you improvements!

If you interested in Scrum, I start reading this book http://scrum.org.ua/

Nice to meet you!

P.S. Now I read about Python Jango framework and have add many good features to out phpDays framework. I recommend you see on Python - this good language for web and for us!

2009/11/18 Ira Go <let...@gmail.com>

Ira Go

unread,
Nov 26, 2009, 2:44:10 AM11/26/09
to phpDays - php5 framework

> Thanks for you improvements!
Is it a go? Can I replace the set() method with a shorter one?
>
> If you interested in Scrum, I start reading this bookhttp://scrum.org.ua/
What book do you mean?

I think I'll look at Ruby and Ruby on Rails. Thanks for the pointers!

Anton Danilchenko

unread,
Nov 26, 2009, 3:24:03 PM11/26/09
to php...@googlegroups.com
Сейчас я изучаю Питон и Джанго. Узнал многое новое для себя. Классный язык Питон. однако!

2009/11/26 Ira Go <let...@gmail.com>
Reply all
Reply to author
Forward
0 new messages