Author:

When you cant focus

In the past few weeks/months, I didn’t have my focus on one specific thing, I was doing multiple things at the same time, I tried to study English to improve it and have better score, I tried to read more about PHP (as each day pass I feel that am losing and forgetting everything I used to know once about PHP), and Finally I was also reading and trying to expand my knowledge for Docker.

I know that this is not a normal situation, but things are not getting any easier, every day a new thing to deal with, a new problem or a more complicated situation to think about and try to figure a solution for it, many I can’t do much as it is out of my control.

I always said and keep saying that am not a real programmer for many reasons, I didn’t study computer engineering nor computer science, I studied Information Technology which has some interaction with programming, but not as deep as computer science for example, and this is one of the reasons why I don’t stop reading books about programming, I always feel that there is something missing that I don’t fully know so I need to search and try to figure it out.

And many times sadly, I spend a lot of money on books that I don’t have time to read or resources that I found not as useful as I thought it would be for me. Which sadly leaves me with too much time to spend with the family. and am so lucky to have family/wife who supports me, and supports my premonition of reading and filling the gaps.

But this does not make me less than any good programmer out there, which is something I know, but I always try to forget and pretend that am not that good, so I keep doing what I do best, annoy everyone around me with my premonition.

Right now I have a lot of things to do, and so little time to do them all, but am trying, maybe not my best yet, and not sure when my best will come out, but at least am still trying and don’t want to stop.

So what’s next, I have no idea, but I know that I need to fix my English and try to understand the new terms in the PHP world that everyone is using nowadays.

Sometimes when you spend too much time working on one project, you will lose touch with the outside world as your focus will be to get the project done correctly, not in the fancy way that every new term likes to shine.

Anyway, it’s me talking before going to bed, so am sure none of what I have just said will make any sense.

Filed under: Books, Personal

Testing upload file with Slim 3 (a better way)

In my last article, I talked about how we can mock the upload functionality, but without testing the existing of the file, this will work with you without any problem, but now to test the existence of the file we can do it like this:

This is the content of the upload function from the upload controller:

As you can see nothing too fancy, we get the uploaded files, we check that the upload worked then we moved the file to the storage directory, now the testing for the functionality with a real file will be like this:Continue reading

Filed under: Code, PHP

Testing upload file with Slim 3

 

Alert! This may not be the correct way, but sadly enough I didnt find any resources about this topic, most articles talk about Laravel, so if you know better way please write it in the comments. Thanks
Automatic testing may not the best topic I can talk about, at least for now, but it’s something that am committing to learn. So yesterday I was playing with Slim 3 (which is a PHP microframework) and I needed to try and see if I can test a dummy controller which upload a file and store it.

I went to the mighty and only one Google, but most of the articles was about Laravel or how you can mock the file system with vfsStream, and that’s was not what I want, so after playing for few hours I got through 90% of it, as I still need to test the existing of the uploaded file.

So here are my notes, and how I did it:

1- You will need to modify the base test file (BaseTestCase.php), so you can pass to it the uploaded file.

Continue reading

Filed under: Code, PHP

Why I write in English

Everybody around me knows that English is not my mother language, and how much I like to write in Arabic, but why do you think I have archived my Arabic blog (which I started in December 2004) and started an English one?

Yes I know am not that good in English, and I have a lot of things to work on, so again, Why did I start to write in English? to be honest, the answer may not be a simple one, but at least to me, the answer is that I do need to Improve my English and the way I write.

So yes you will find a lot of grammatical mistakes, and maybe using the wrong terms or phrase, but at least am trying my best.

Reading technical books, and even self-published books, will not enhance my English, sometimes it may make it worse, as this is the hype nowadays, and am somehow a person who leak the power to not spend his money on things that he might think he will read one day, and Yes I do use English in my work, but everyone knows that we always try to excuse those who don’t speak English as their first language, and try not to embarrass them, but just read and reply as long as we understand the general idea.

Anyway, I hope by more writing and using Grammarly this will change, am still using the free version, not sure when I’ll upgrade or if am going to upgrade anytime soon.

That’s all for today.

Filed under: Personal

What you should use to write a CLI app

I was going to write a post about this, but then I found out that I don’t have a big plan for what am going to write, so instead, I prefer that you go and read this article: Re-Introducing Symfony Console – CLI PHP for the Uninitiated! its not exactly what I wanted to write, but why to re-write things when someone already did that.

Intro:

As a web developer, we are always fascinated with what we can do for the web, we have the best technologies ( not including old IE version ), we have some limitation, but now we can also use web technologies to develop Desktop apps. So talking about CLI apps may not be the best topic here, but sometimes its way better to use CLI to develop an application than using the normal route with nginx/apache, why you may need to do that? the reasons are unlimited, the main one is your judgement.

First of all developing CLI application with PHP does not differ that much from developing Web app, you will use the same code, but your user will interact with the app via Terminal not Visual UI, this can be helpful when you are doing something like processing big files,  CSV files, or maybe doing some maintenance. You will need to care about the structure of your app, and how you code, at the end you don’t want to spend a lot of time trying to debug it and even losing control and make it way complicated than it should. so lets start to show you how I do it, then you may use the same or even better technique to develop your own.

Required Components:

There are a lot of libraries which we can utilize to develop the code, as with web you are not limited to specific framework or library, you can create your CLI with nodejs or even better with PHP ;) , for me I depend on PHP so I’ll list all the libraries that I use here:

  1. Symfony Console : http://symfony.com/doc/current/components/console.html
  2. Symfony Process : http://symfony.com/doc/current/components/process.html

Symfony Console is the main component here, which will help us to build a Command Line Application (also known as CLI).

Filed under: Code, Linux, PHP