Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Matthias Noback:
Mocking at architectural boundaries: persistence and time
Feb 22, 2018 @ 17:07:35

In a new post to his site Matthias Noback takes a look at unit testing your code and how it can be "dangerous" if you use mocking/doubles in the wrong way (not effective testing). Instead, he makes the recommendation to mock at architectural boundaries, specifically looking at mocking persistence and time handling.

More and more I've come to realize that I've been mocking less and less. The thing is, creating test doubles is a very dangerous activity.

[...] For example, by creating a test double for the EntityManager, we're assuming that it will work well with any objects we'll pass to it. If you've ever debugged an issue with an EntityManager, you know that this is a bad assumption. Anything may go wrong: a mistake in the mapping, missing configuration for cascading persist/delete behavior, an issue with the database credentials, availability of the database server, network connectivity, a missing or invalid database schema, etc.

He then gets into the concepts behind mocking across the "architecturally significant boundaries" and what kind of functionality this involves. He then gets into the two different examples sharing some of the basic concepts and test examples for evaluating persistence and time handling. He finishes up with a look at some of the potential consequences ("outcomes" is really a better word) of refactoring your tests and code to follow these ideas.

tagged: mock unittest architectural boundary persistence time tutorial

Link: https://matthiasnoback.nl/2018/02/mocking-at-architectural-boundaries-persistence-and-time/

Daniel Cousineau's Blog:
Calculating Daylight Savings Time Boundary In PHP
Mar 11, 2009 @ 17:02:15

Daniel Cousineau has written up some timely advice in a new post to his blog. It looks at pinpointing the time boundary for Daylight Savings Time in a PHP script (when it starts and when it ends).

I had an issue recently where I needed to calculate the Unix timestamp for the daylight savings time boundaries. According to the United States Naval Observatory, daylight savings time begins the Second Sunday of March and ends on the First Sunday of November.

He looks at using the strtotime function to calculate these dates but points out some quirks - like what happens when you just give it a month or something like "second Sunday". His solution was to go back one day ("March 0" instead of "March 1") and calculating the time from there, including that first full day of March in the calculation.

tagged: calculate daylight savings time boundary march november strtotime

Link:


Trending Topics: