PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
It is currently Tue Sep 29, 2020 3:27 am

All times are UTC - 5 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Sun Nov 08, 2009 10:10 am 
Forum Newbie

Joined: Sun Oct 05, 2008 5:17 am
Posts: 2
I have a class ('Authenticate') with a method Authenticate->login() that itself calls the method of an Adapter class 'AuthenticateAdapter->authenticate(username, password)' to check the username/password combo in a data source. I want to test Authenticate->login. How do I set up the Adapter class call within login()? Do I use a stub or mock object - not really sure I understand either...

PostPosted: Mon Mar 29, 2010 12:30 pm 
DevNet Master

Joined: Wed Feb 11, 2004 4:23 pm
Posts: 4872
Location: Palm beach, Florida
Stub out the adapter, and inject that into your login service.

On the first test the adapter would return true, on the next test it would return false. You would test that the login service is reading that return value back in and acting on it appropriately.

Mock objects differ from stubs in that they verify outbound calls that have no side effects that you can sense.

If you can test the state of the system under test, that is best. A mock object should be used when testing the state of the SUT is awkward. Mock objects can result in over specified software, and high test maintenance cost, two major project "smells".

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group