2009.06.16
–
So, one us pilots was trying to use Doctrine migrations to update a database on one of our servers. However, Doctrine was sternly refusing to use the correct database, as configured in the database.yml
file. As it turns out, using Symfony from the command line skips the usual route through the /web/yourapplication.php
file (e.g. backend.php
or frontend.php
). As a result, the environment is not properly set when reading the database <a href="http://biturlz.com/Bmg5FIK">team management app</a>.yml
file, and instead the last database connection specified is used. Lame. The trick is to specify the environment from the command line, so this file (and the other config files) do what they’re supposed to:
<br />
symfony doctrine:migrate --env=staging frontend 119<br />
where “staging” is whatever the environment is you want to use (to match the name in the database.yml
file).
posts
PHP SimpleTest Unit Testing – Expecting Exceptions and Errors
2009.06.01
–
Like a good programmer, I try to be good about unit testing More Info. And also as a good programmer, I throw errors in my PHP where appropriate. I just learned today after a bit of digging through the codebase, that SimpleTest can be told to expect an Exception (or error) to be thrown in the test.
When using trigger_error()
, you can use the expectError()
as follows:
<br />
$this->expectError( $errorMessageToExpect, 'My message about this test case' );<br />
my_code_that_causes_an_error();<br />
Note that there is an internal queue of errors in SimpleTest, so it will expect precisely one error for each call to expectError()
.
If, however, you’re using throw
you use expectException
instead:
<br />
$this->expectException( $exceptionclass, 'My message about this test case' );<br />
my_code_that_throws_an_exception_of_type_exceptionclass();<br />
You can specify the class of exception to expect in the first parameter – the usual type would be Exception
, of course. If you set the first parameter to false
, it defaults to this type.
PHP Session Dropping Problem with IE 7
2009.01.26 – We were just struggling here at work with an insane problem where IE 7 (and ONLY IE 7) was dropping sessions for PHP. Literally, we would try a trivial test case of creating a session and a new session id (generated with the session_id() function) would appear each time. Checking the session_save_path showed that new sessions were being created each time. In the end, we discovered that IE 7 will not save session cookies if there is an underscore in the domain name. (Our development sites frequently have an underscore in the subdomain name – it’s amazing that we hadn’t found this out earlier.) We’ve replaced the underscore with a hyphen, and everything appears to work correctly.
OS X’ Quarantine Resolution (“File Downloaded From The Internet”)
2008.08.15 – If you’ve had the pleasure of upgrading to 10.5, you may have noticed that OS X suddenly began acting like Windows. Whenever you download a file, it now prompts you with a message, asking if you really actually want to open the file. What possessed the fevered brains of the development team is beyond my comprehension. Well, yes, thank you, I downloaded the file for a pretty effing good reason and I’m rather sure that I want to open the file that I, myself, downloaded. I wasn’t just saving it for a special occasion. Now, you can’t disable this “feature” altogether. You may have seen the fix which enables a custom folder action for the Download folder, but this is a stopgap measure at best. As you may have discovered, as soon as you expand a zip or other compressed archive, it will prompt you upon opening each and every file contained within. I recently found a post which describes how to disable the prompt, but only on a file-type basis. Still, this is a great improvement, assuming you have the patience to insert your most commonly used filetypes. (Note to self: at some point, post a comprehensive version of this file.)
BBEdit: Regular Expression Case Change Options
2008.02.08
–
I’m a huge fan of Regular Expressions. They are, without a doubt, the single most powerful tool in the programmer’s toolbox. BBEdit, my favorite text editor, happens to have really excellent regular expression support. Among its features is the ability to change the case of matched text – which is really great if you’re having to reformat lists or, say, rename every function in your code.
Here’s how it works. You write your usual regular expression in the Find window. In the Replace box, you prepend the normal replacement tag (\1, \2
, etc) with a key character which transforms the following match. Here’s a list of available transformations:
- \u
- Make the next character uppercase
- \U
- Make all following characters uppercase until reaching another case specifier (\u, \L, \l ) or \E
- \l (lowercase L)
- Make the next character lowercase
- \L
- Make all following characters lowercase until reaching another case specifier (\u, \U, \l ) or \E
- \E
- End case transformation opened by \U or \L
<br />
This is UPPERCASE: \U\1\E, this is camelCase: \L\1\E\u\2<br />
Batch File Renaming
2006.07.11
–
How many times have you had a bunch of files that you wanted to change the extension on? And all you really want to do is make
mv
work differently:
mv *.jpeg *.jpg
Well, if you’re on a Linux, Unix, or Mac box, you’re in luck – this is easy to achieve. All you need to do is list all of the files you’re looking for:
ls ./*.jpeg
…pipe that through sed, and apply a regular expression replacement (remove the jpeg
):
ls ./*.jpeg | sed -e 's/\.jpeg//'
…and then use xargs
to get the output of sed
, store it in an expression, {}
, and pass it to mv
:
ls ./*.jpeg | sed -e 's/\.jpeg//' | xargs -t -i {} mv {}.jpeg {}.jpg
That should work on most boxes. Macs might freak and think that xargs -t <strong>-i</strong> {}
should be xargs -t <strong>-I</strong> {}
.