Running specific tests using Gulp TDD in Laravel Elixir

Today my team was trying to refactor some code and we wanted phpUnit to continually tell us if anything was breaking. Jeffrey Way’s excellent Elixir package that is included with Laravel now includes the option to run gulp tdd which watches the tests being edited and runs the tests once the files are saved. In our case today, however, I didn’t want it to run all of the tests since we have a fairly significant test suite. I’ll quickly go through a few ways this can be done!

To be clear, below is all that it takes to get Laravel Elixir up and running using phpUnit. Once you have added this mix.phpUnit(); to your gulpfile.js, all you need to do is run gulp tdd from your command line and you are off to the races!

elixir(function(mix) {
    mix.sass('app.scss');
    mix.phpUnit();
});

After looking through the gulp-phpunit API and the Elixir implementation, I realized there were two options that could be passed into mix.phpunit(). They are mix.phpunit([src], [options]).

[src] specifies where phpUnit should look for the source files to run against. In my case, I have a set of directories inside my tests folder so my value for src needed to be ‘/tests/**/*Test.php’. This will run inside one level of subdirectories with any file that ends with Test.php.

[options] is where you can go all kinds of crazy passing things into phpUnit. All you need to do is pass in an object with whatever settings you would like to use. Many other things can be passed in other than just a specific class. For the entire listing of options that can be passed in, go to https://github.com/mikeerickson/gulp-phpunit#api and check out the API documentation for the gulp-phpunit package.

So what did the entire thing look like once it was completed?

mix.phpUnit(['tests/**/*Test.php'], {
    testClass: 'tests/TestSubdir/SpecificTaskTest.php'
});

Another way this could be done is by using the filter option which allows a pattern to be passed instead of a specific file. Say I have 3 files in my TestSubdir that I want to run and they are named SpecificTaskTest.php, SomeOtherTest.php, and AnotherTaskTest.php. I could specify a pattern of *TaskTest.php and it would run the two tests that end in TaskTest.php. The way this would be used is as follows:

mix.phpUnit(['tests/**/*Test.php'], {
    filter: 'tests/TestSubdir/*TaskTest.php'
});

Check out the latest documentation for additional filter examples if desired: https://phpunit.de/manual/current/en/textui.html#textui.examples.filter-patterns. You can also use a testSuite or a group to specify the individual tests that should run.

One of the other interesting options was configurationFile. With this, you can actually specify a different phpunit.xml file to be used when running gulp tdd. I could see this being useful in instances where your tdd workflow looks a bit different from when you run your entire test suite (perhaps with code coverage or other more time-consuming tasks that you may not want to run when performing quick tdd/refactoring).

Testing Private Methods in PHPUnit

A few days back I was running a code coverage report in PHPUnit. If you haven’t used a code coverage report before, it basically shows the codebase, and identifies locations where your code is covered by tests and areas that are not ever hit when running your test suite.

As a result of running this report, I realized there were a few critical holes in a particular method. I had a transformation method on one of my api gateways that Highlighting was parsing the data being returned and then presenting my application with a consistent result that I could count on. Some of the cases that could happen, however, were not covered in my test suite.

Since the third-party API Erfurt endpoint I was hitting didn’t allow me to specify the data I could possibly expect to get back, I wanted to be sure the code I had written to standardize the results was consistent with how I thought it would run. In this instance, I wanted to actually test how specific use cases would be handled, but one of the methods being called was a private method and I wanted to test it individually.

My solution to solving this problem was found in the ReflectionClass in PHP. The reflection class essentially reports information about a given class (for more information, check out php.net’s detailed information. I created a method called invokeMethod() that wholesale nba jerseys allows den us to essentially run a private method individually.

public function invokeMethod(&$object, $methodName, array $parameters = array())
{
    $reflection = new \ReflectionClass(get_class($object));
    $method = $reflection->getMethod($methodName);
    $method->setAccessible(true);
    return $method->invokeArgs($object, $parameters);
}

This method is called by creating a new instance of a class, and then passing it & in:

$myClass = new \App\CustomClasses\MyClass();
$state = $this->invokeMethod($myClass, 'retrieveState', array('Madison, WI'));
$this->assertEquals('WI', $state);

The API just returns data from a claim system that will sometimes include a City/State, just cheap jerseys a State, or a City/State/Zip and what I specifically need is the state abbreviation. This allowed me to effectively call $this->retrieveState(); even though it is a private method and ensure what I expect to get back in many instances is always correct. Important? By being able to call this private method, I was able to test things like:

$myClass = new \App\CustomClasses\MyClass();
$state = $this->invokeMethod($myClass,  command  'retrieveState', array('Wisconsin'));
$this->assertEquals('WI', $state);

and

$myClass = new \App\CustomClasses\MyClass();
$state = $this->invokeMethod($myClass, 'retrieveState',  Legislative  array('Madison, WI 12345'));
$this->assertEquals('WI', $state);

I understand there is also a possibility of being able to mock the response and then perform tests that way, wholesale nfl jerseys but this felt very clean and it was extremely clear to the other developers who were also looking at the code. Sound off in the comments below if you have other thoughts and I can update this post as appropriate.

Backing up MySQL databases on Windows from the command line

I’ve been working on a bunch of internal projects at my company and had the need for a previous version of the database. While I could certainly have restored from a backup of the server, it got me thinking about how slick it would be to have mysql backups performed at certain intervals (daily, weekly, etc.) that I could quickly reference in the in event it was needed quickly.

Windows Batch File

The cheap nba jerseys first step to perform is to create a simple batch file (I called mine mysql_backup.bat).

Once that file is created, the proper instructions are needed to invoke the mysqldump feature native to MySQL.

The entire command will end up looking like this:

mysqldump  we  -u "username" -p "password" > output_file.sql

mysqldump

Depending on where you intend to run your batch file from, you may wish to just specify the actual path to the mysqldump executable. For my particular installation, the mysqldump command was loaded wholesale nfl jerseys at: C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump. In the event ?????? the path has spaces, it will need to be quoted in the batch file.

Username/password configuration

It is important to note that the username and password must also be included in the command line string.

-u username -p password

Database selection / output file name and location

After the username and password strings, the database name along with the output destination should be specified.

databasename > mysql_backup.sql

In my case, I wanted to actually write my backup files to a network share on another server. This is easily accomplished. Just pass in the complete path:

databasename >  2010  \\fileserver\share\backups\mysql_backup.sql

Complete Command String

So what does the complete command string look like to run a MySQL backup from a batch file in any location?

"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump" -u username -p password databasename > \\fileserver\share\backups\mysql_backup.sql

What about backup file encryption?

Windows comes with a pretty slick tool called Cipher. Using this tool, you can actually encrypt the files cheeses when they are backed up. Keep in mind that the instructions below only show the basic methodology for enabling encryption on the file. Most likely you would want to generate a key and store in a secure location, etc. The cheap nba jerseys command string to run a backup and initiate file encryption is as follows:

"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump" -u username -p password databasename > \\fileserver\share\backups\mysql_backup.sql && cipher /e /a \\fileserver\share\backups\mysql_backup.sql

The command above will call the cipher command (using /e – encrypt and /a – for a particular folder or file) on a particular file that should be encrypted.

Running the batch file

Depending on the options listed above, save the contents of the command string into the batch file you wish to run. Save the batch file in a location on the machine where MySQL is installed. If you have included the entire path to the mysqldump executable, you should be able to run it from the location where you save it. Once you have is saved the file (with a .bat extension), double-clicking on it will actually run the script. Note: If you want to edit the batch file, simply right-click and select edit or open it with your favorite text editor.

Scheduling

Once you have a batch file that is working correctly, you will most likely want to schedule it to run on a routine basis. Windows Task Scheduler works well. Simple open Task Scheduler on Windows, click Create Task. On the Actions tab, click New… and then select Start a program from the dropdown menu. Simple type in the path to your batch file you have created and you are just about done! Simply select the schedule you want it to run on and then save the scheduled task. You Benefits can right-click on it and run it immediately to ensure it has been configured correctly.

PICK Basic Syntax Highlighting in Sublime Text 3

I have recently been writing a bunch of code in PICK/BASIC. The main line of business application at my existing company is built on top of the Rocket Universe platform and building custom subroutines and cheap jerseys dictionary elements is wholesale MLB jerseys usually done in PICK/BASIC. I typically use Sublime Text 3 for code editing but Day it lacked syntax cheap jerseys highlighting for PICK/BASIC which can Package make syntax errors more common.

My coworker Jake Bennett initially built Important? a PICK syntax highlighting file for me that worked with Sublime Text about a year and a half ago so I decided to fork his project on GitHub and make some additional changes. He had done an excellent job building an initial version based on the information he was given. Over the past few days I have tweaked the syntax file even more so that it works pretty well for the type of code I am writing and I have updated the files on GitHub (https://github.com/jordonbrill/sublime-pickbasic). If you have any additional things you would like added, feel free to mention them in the comments below, open a pull request, or open an issue on my GitHub page.

If you have not installed a custom syntax file before, I wholesale nba jerseys have included the instructions below:


Using Custom Syntax Files in Sublime Text 3 in Mac OS

To add custom syntax files using a Mac, open the following directory in Finder: Users/username/Library/Application Support/Sublime Text 3/Packages/

If you have git installed, you can just run:
git clone https://github.com/jordonbrill/sublime-pickbasic.git from inside the Packages directory listed above. If you install it from GitHub, when I update the syntax files in the future you will be able to update the files with a simple git pull command.

If you do not have git installed, you can navigate to my GitHub page linked to above and click Download Zip. That will download a zip file which can be Professional extracted and placed into the Packages directory.

Once you have placed the folder into the Packages directory, quit Sublime Text 3 and reopen it. If you select View > Syntax you should see a Pick Basic option in Mangiatoia your dropdown menu. Alternatively, you can invoke wholesale NFL jerseys a keyboard command Command + Shift + P and they type “Pick Basic” and it will filter the options to allow you to set the syntax to Pick Basic.

What is Important?

Its 1:30am and you are still awake. Sitting on the recliner with your laptop open staring at the screen. You needed to grab your power-cord about 2 hours ago because your battery was at 3% and your laptop was going to sleep in about 5 minutes.

I was determined to not let my MBA get in the way of spending time with him.

This was my story. I’m Jordon and I just finished my Masters in Business Administration (MBA) from Cedarville University. Of course, late nights are typically part of the process in education, but there is another reason I was usually up late working on my classes. You see, in May of 2013 a certain little boy was born. In just a few short months I would be starting my MBA but I quickly fell in love with this little guy. I was determined to not let my MBA get in the way of spending time with him.

Only after 9…

As my son got older and was able to crawl and then walk, I started spending more and more time with him when I would get home from work instead of starting on school. As a rule, I wouldn’t typically start working on school until 9pm. This gave me 4–5 hours with him before he went to bed. You see, I don’t get very much time with him and the time that I do have while he is awake is very important.

Why does this matter?

PeytonThis is something I have been thinking a lot about lately. What drives you to do the things that you do? I now have a beautiful 7 month old daughter as well and she is an absolute charmer! I tend to focus extremely hard on my job and try to do the best that I can for myself and my company. But why? I certainly want to provide for my family and make sure they have the things that they need, however, if all I focus on is making sure they have all of the money for the things they need but don’t actually Clean have cheap jerseys time to spend with them, what’s the point? I have been able to excel in my professional career while still maintaining a work-life balance. Family is important.

A plumbing project

My dad was an amazing example of love for family. He taught me to work hard and to love family. I remember my dad working on his college degree when I was little and he would hold me on his lap to study through flashcards before a test. I remember him working on a plumbing issue under the sink and me and my brothers would be climbing all over him to “help” fix the problem. Now, 25 years later, I am thankful he made family so important.

That annoying little kid…

My son loves to spend time with me and I try my hardest to ensure he always knows he is welcome and wanted. When Basics I’m mowing the lawn, he wants to walk with me behind the lawnmower and reach up as high as he can to just barely grab the handle; I even lowered the handle down a bit so he can hold it easier. Its certainly not easier for me to push the Micah & Daddy Mowingmower with the handle so low, but I’m mowing with my son and that is all that matters.

When I get home from work, he comes running to the door and shouts “Daddy. Home. day Truck. Lawnmower.” He hasn’t mastered prepositional phrases yet. He’s still working on verbs, honestly, but wholesale nfl jerseys it makes me super happy to hear his voice and see the door open as I’m walking into the house.

I want to be the dad whose kids understand how much they are loved. I never want them to feel as if they can’t come sit on my lap or ask to ride along with me in my truck. I love sitting at the dining room table eating ice cream with them.

If you have kids, embrace them! Show them they are loved.

Micah with hammer in bathroomThings will always take longer with them around than they did before, but that is okay. cheap jerseys China Coming to the understanding that these little people are your responsibility is sobering and exciting all at the same time. If you have kids, embrace them! Show them they are loved. Tuck them into bed at night. Read them books. Take them on walks. Give them a hammer and nail and show them how to use it. Let them run in the rain. You will never regret it.