When the operating system instructed one of the active cores to enter C3 sleep state using the Advanced Configuration and Power Interface (ACPI), the other active core(s) dynamically accelerated to a higher frequency.

I realized that you need to make sure you have the ACPI C3 state option enabled in your BIOS. Some users who are looking to make their i7 perform the highest by disabling power saving features may actually be disabling the highest speeds for single core operations. I enabled this and now I get 3.9Ghz speeds:

Moral of the story – don’t disable ACPI to try to gain faster speeds, you might lose single/duel core turboboost!

Mocking is great for very lean unit tests. It allows you to setup a repeatable scenario to test as many of the states of a unit as you want. In general, I want to be testing only a single method or a single class. If you’re testing more than this, you’re not writing unit tests – you’re writing integration tests! A good measure on if you are writing proper unit tests would be to change something in the code to make a test fail. If you end up with a cascade of tests fail, you have integration tests, not unit tests!

So in unit testing, you want to be able to isolate a single unit and manipulate the inputs to cover all types of conditions and verify the validity of the outputs to those conditions. I like to think of it like an algebraic inequality problem. You always check your boundaries and then a value within the different boundary regions. Think of it similarly with unit testing.

As you can see with the example, sometimes inputs and outputs of functions are not always so straight-forward. While we can have our standard input and output passed from the method parameters and the return value, more often than not, inputs and outputs are received and sent by calling other functions. With mocking though, this is no issue. We can mock any function and define exactly what it should return. We can also test and verify that the function was called.

We are creating a new Calculator mock. The first parameter tells phpunit what class to mock, the 2nd parameter tells phpunit to only mock the ‘getNumberFromUserInput’ function and not anything else. We need to use the real divideBy() function to test that. getMock() has a lot of useful options, refer to the api or Mark Mzyk’s blog post I found on the getMock method signatures.

Line 1: We are saying here that we expect this method to be called once. If it is called less or more than once, we will get an exception.

Line 2: The method name we are mocking out.

Line 3: The return value of the mocked out function. You can also throw exceptions, return back one of the arguments unmodified, or even call another callback function. The code for that is $this->throwException(new Exception()), $this->returnArgument($ArgumentNumber) and $this->returnCallback($callbackMethod) respectively. With the callback, all the parameters you pass to the mock will be passed to the callback.

Anyways, back to our example, I ran the tests and we see at our 0 boundary that we get behavior that we were not expecting and our tests fail.

->with() will test the that the method is called with parameters passed. If your original function has multiple parameters, just add them in as multiple arguments to with(). ->with($this->equalTo($param1), $this->anything(),$this->equalTo($param3)). You can use any of the constraints that phpunit supports – http://www.phpunit.de/manual/3.2/en/api.html#api.assert.tables.constraints

I seem to do this everyday on the job when I am coding and then forget on those weeks that I don’t code. Here’s the quickest way to create a remote branch that is tracked locally and remotely.

1
2

git checkout-b new_branch_name
git push-u origin new_branch_name

No fiddling around with git branch creation and checkout, then –set-upstream, All done in those 2 commands. The first command creates a new branch and sets that as your working tree. The second command pushes the current branch upstream to origin and at the same time handles –set-upstream to the given location. Neat?

While we’re at it, here’s how to delete it if you don’t need it anymore.